• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Unix command and scripts » How to insert line after match using sed

How to insert line after match using sed

January 1, 2019 by techgoeasy Leave a Comment


I was working on certain project last week where i need  to insert line after match in 100 of files in Linux or Unix operating system. I found that insert line after match using sed is easy. It was quite  successful for me ,so i thought i will share this on my blog.

Let’s take an example to understand it

We have a html file like below

$ cat test.html
<html>
<head>
<title>This is test</title>
</head>
<body>
This is test page
</body>
</html>

I need to enter certain text after like <body> in the file

we can achieve it using sed with append

sed -e ‘/<body>/a  Welcome everybody’ test.html
<html>
<head>
<title>This is test</title>
</head>
<body>
Welcome everybody
This is test page
</body>
</html>

if I need to enter certain text before  like <body> in the file

#sed -e ‘/<body>/i Welcome everybody’ test.html
<html>
<head>
<title>This is test</title>
</head>
Welcome everybody
<body>
This is test page
</body>
</html>

So far the above command just changes the output. File is not changed. If you want to change the file also

we can do with -i option

#sed -i -e ‘/<body>/a  Welcome everybody’ test.html
#cat test.html
<html>
<head>
<title>This is test</title>
</head>
<body>
Welcome everybody
This is test page
</body>
</html>

sed insert line after match

You can make these changes in multiple files using *  or giving pattern the file

sed -i -e ‘/<body>/a  Welcome everybody’ *.html

Hope you like this short article on sed. Please do let me know your feedback

Related Articles

Awesome sed command in Linux/Unix with examples

21 awk command examples in Unix/Linux

Useful Unix/Linux command for Oracle DBA

Writing loop statement in Unix shell scripting with examples


Filed Under: Unix command and scripts

Reader Interactions

Leave a Reply Cancel reply

Primary Sidebar

Top Posts & Pages

  • How to check Tablespace in Oracle -Size ,Free space,datafiles ,growth
  • how to check all constraints on a table in oracle
  • Query to check table size in Oracle database
  • Oracle dba interview questions and answers
  • Oracle Indexes and types of indexes in oracle with example



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • How to run Autoconfig on Patch system in R12.2
  • Admin scripts in R12.2 Ebuisness Suite
  • Timezone settings in Oracle database
  • how to enable trace in oracle apps r12
  • Transparent Data Encryption Queries

Copyright © 2021 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us