sed insert new line does not update file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed insert new line does not update file
# 1  
Old 05-03-2013
sed insert new line does not update file

Hi all,

I have a file called "text.cpp" with the first line of "1"
afterwards I tried in Ubuntu to type the following

sed '12iasdasdasdasdsad' test.cpp > output.txt

however when I tried to see the result of output.txt

#cat output.txt
1


why is the line 12 is not updated to the new output.txt? Smilie


thank you
# 2  
Old 05-03-2013
Code:
sed '12i\
asdasdasdasdsad' test.cpp > output.txt

you must add a new line after your backslash .

Last edited by mstafreshi; 05-03-2013 at 07:31 AM.. Reason: more description
# 3  
Old 05-03-2013
---------- Post updated at 05:31 AM ---------- Previous update was at 05:30 AM ----------

Quote:
Originally Posted by mstafreshi
Code:
sed '12i\
asdasdasdasdsad' test.cpp > output.txt

still does not update the output.txt .. it consist only "1" even after I removed the old output.txt
# 4  
Old 05-03-2013
What that sed is doing? and what you want to achieve from this?Smilie
# 5  
Old 05-03-2013
Quote:
Originally Posted by vidyadhar85
What that sed is doing? and what you want to achieve from this?Smilie
I have a test.cpp with a "1" on the first line. I want to copy this respective file to other file with additional lines in line 12..
# 6  
Old 05-03-2013
your file has at least 12 lines ?
# 7  
Old 05-03-2013
Ok, I found a similar way
Code:
sed '1i\
> your text goes here' test.cpp > testfile.txt


thank you everyone!Smilie

Last edited by Franklin52; 05-03-2013 at 08:35 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

sed insert into line 1 via script

Hi I am trying to run a sed command within a script..unfortunately it wasn't written on Solaris so doesn't work. Can anyone help with the correct coding please? It is: sed -i '1i ROWID;ORDER_ID;JOB_NAME;ORDER_TABLE' ${OUTFILE} (4 Replies)
Discussion started by: Grueben
4 Replies

2. UNIX for Dummies Questions & Answers

sed command to Insert a line before the last four lines of the file

By using sed command, How to insert a new line before the last four lines of the file. Old Line Old Line NEW LINE! Old Line Old Line Old Line Old Line (8 Replies)
Discussion started by: wridler
8 Replies

3. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

4. Shell Programming and Scripting

Insert output from a file to beginning of line with sed

Hi I've been trying to search but couldn't quite get the answer I was looking for. I have a a file that's like this Time, 9/1/12 0:00, 1033 0:10, 1044 ... 23:50, 1050 How do I make it so the file will be like this? 9/1/12, 0:00, 1033 9/1/12, 0:10, 1044 ... 9/1/12, 23:50, 1050 I... (4 Replies)
Discussion started by: diesel88
4 Replies

5. Shell Programming and Scripting

Insert @Line # - SED (non-GNU)

Just posted on another fellow's question using ed, but I wanted to know about doing it with sed on Unix. For example - I have a file of an unknown length, but I want to add a line after the shell declaration (Line 2). If possible, I'd like the example to be able to just substitute in a number and... (2 Replies)
Discussion started by: Vryali
2 Replies

6. Shell Programming and Scripting

Insert/Update using sed

Hi, I have a xml file (Config.xml) with following entry <Date="" Node1="50" Groups="20"> Now I want to use sed to insert/update the Date field with the latest date say - 20120711. I can't use a simple replace command becuase the Date field could be blank ("") or sometimes could have value in... (9 Replies)
Discussion started by: vivek_damodaran
9 Replies

7. Shell Programming and Scripting

Using sed to insert text file at first line

sed '1r file.txt' <source.txt >desti.txt This example will insert 'file.txt' between line 1 and 2 of source.txt. sed '0r file.txt' <source.txt >desti.txt gives an error message. Does anyone know how 'sed' can insert 'file.txt' before the first line of source.txt? (18 Replies)
Discussion started by: psve
18 Replies

8. Shell Programming and Scripting

Sed insert text at first line of empty file

I can't seem to get sed to allow me to insert text in the first line of an empty file. I have a file.txt that is a 0 byte file. I want sed to insert " fooBar" onto the first line. I've tried a few options and nothing seems to work. They work just fine if there's text in the file tho. Help? (4 Replies)
Discussion started by: DC Slick
4 Replies

9. Shell Programming and Scripting

sed - how to insert chars into a line

Hi I'm new to sed, and need to add characters into a specific location of a file, the fileds are tab seperated. text <tab> <tab> text <tab> text EOL I need to add more characters to the line to look like this: text <tab> <tab> newtext <tab> text <tab> text EOL Any ideas? (2 Replies)
Discussion started by: tangentviper
2 Replies

10. Shell Programming and Scripting

SED: Update Last Line with Number Lines in File

Hi, I have to update last line of a text file with the number of lines in that file. This last line will have text such as 0.0000 and I should replace this with number lines. If lines are 20 then it should be replaced with 00020. Any sed or awk cmd help would be appreciated (3 Replies)
Discussion started by: bmkux
3 Replies
Login or Register to Ask a Question