sed to add a new line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed to add a new line
# 1  
Old 07-16-2010
sed to add a new line

Hi

In my sed version the interactive method of adding a new works :
Code:
> sed '3a\
new line ' file_name

But i want to do the same task in one command as it is a part of a script.

i hav tried the following but no luck so far
Code:
cat file_name |sed -e '3a\ new line '
 
cat file_name |sed -e '3 a  new line '

Anyone please help on this one...

Last edited by pludi; 07-16-2010 at 03:07 AM..
# 2  
Old 07-16-2010
with gsed:


Code:
cat file_name | sed -e '3a\ '




if you just want to add a new line:

Code:
sed 3G file_name

should work with all versions of sed
# 3  
Old 07-16-2010
I want some text not a blank line...

and i hav already tried your 1st method...

Code:
> cat file2 |sed -e '3a\ "mytext" '
sed: command garbled: 3a\ "mytext"
> cat file2 |sed -e '3a\ mytext '
sed: command garbled: 3a\ mytext

Is the any other alternative...?

---------- Post updated at 04:55 AM ---------- Previous update was at 04:46 AM ----------

for now I am using

Code:
cat file |sed 3G|sed 's/^$/mytext/'

Smilie

Last edited by Franklin52; 07-16-2010 at 07:32 AM.. Reason: Please use code tags
# 4  
Old 07-16-2010
Code:
sed '3a\^Jblubbblubb' file

^J is control+v control+j
# 5  
Old 07-16-2010
By awk:

Code:
awk 'NR==3{$0=$0"\n new line "}1' file_name

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed to add a line to a file

Hi, I am trying to add a line to a file using sed. tmp1: aaaa Hello bbbb Hello I need to add "testing" after the first match of Hello. So the output should be aaaa Hello testing bbbb Hello and the line to be added will be a variable (2 Replies)
Discussion started by: giri_luck
2 Replies

2. Shell Programming and Scripting

sed add line to config file

what is the sed command line to add a line to a config file config file name is "config" line to be added cpuid.7.edx = "----:00--:----:----:----:----:----:----" thanks (4 Replies)
Discussion started by: tdubb123
4 Replies

3. Shell Programming and Scripting

Sed/grep: check if line exists, if not add line?

Hello, I'm trying to figure out how to speed up the following as I want to use multiple commands to search thousands of files. is there a way to speed things up? Example I want to search a bunch of files for a specific line, if this line already exists do nothing, if it doesn't exist add it... (4 Replies)
Discussion started by: f77hack
4 Replies

4. Shell Programming and Scripting

sed to add text in new line

help i need to add a "nfsd" in new line after cron ex: cron rpcbind output: cron nfsd rpcbind i use sed -e "/cron/G; s/$/nfsd/" myfile output: cron nfsd rpcbindnfsd (5 Replies)
Discussion started by: jamilzain
5 Replies

5. Shell Programming and Scripting

sed add after line x new text from file

I've been playing with sed, trying to get it to insert the contents of somefile.txt after line 13 on anotherfile.txt. I tried searching for a line with regex and attempting to insert something on the next line with: find ./anotherfile.txt -type f -exec sed -i -e '/^dog/cat/' {} \; but it... (2 Replies)
Discussion started by: unclecameron
2 Replies

6. Shell Programming and Scripting

Want to use sed to add some parameters at the end of the line

Hello All, I have a doubt in sed, i want to add some parameter at the end of the tag inside a xml tag. how to i do that. so i want to add Results="true" value="high" inside the xml tag. Orignal <execute description="reboot"> <execute description="Stop Servlet"> After adding the... (5 Replies)
Discussion started by: asirohi
5 Replies

7. Shell Programming and Scripting

Need to add new line using sed

I need to add a new line using sed based on matching a pattern. I need to add the blank line after the line that I am matching on. Any help? (1 Reply)
Discussion started by: scrappycc
1 Replies

8. Shell Programming and Scripting

SED help (remove line::parse again::add line)

Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions,... (6 Replies)
Discussion started by: Malumake
6 Replies

9. Shell Programming and Scripting

sed.. Add new line after finding text

I know that this my be really simple, but I'm having a hard time accomplishing it. I am trying to add a new line of text after finding a particular string of text in a file. Here's what I'm getting: sed: command garbled: N/search_string/\\new_text/ I was using "N" to add a line after the... (3 Replies)
Discussion started by: douknownam
3 Replies

10. Shell Programming and Scripting

add new line using SED

Hi, I want to add two new lines to a file. I have: dn: uid=beele,ou=medewerker,dc=hva,dc=nl street: Wibautstraat 2-4 dn: uid=beelx,ou=medewerker,dc=hva,dc=nl street: Wibautstraat 2-4 I want to make: dn: uid=beele,ou=medewerker,dc=hva,dc=nl changetype: modify replace: street street:... (3 Replies)
Discussion started by: tine
3 Replies
Login or Register to Ask a Question