Append using SED/AWK


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append using SED/AWK
# 1  
Old 03-11-2010
Append using SED/AWK

Hi friends,

I have a file with content SOME TEXT HERE

I want to append the string GREAT to Line 1 of my file such that the file content should be
GREAT
SOME TEXT HERE

I can do a cat for the string great and file >> newfile and then rename newfile name to file

But this does not put GREAT at Line1. It writes in one single line like GREAT SOME TEXT HERE.

Is there any better way to do this? May be using SED/AWK?

Also please show some pointers to SED/AWk tutorials I would like to start learning them.
# 2  
Old 03-11-2010
Try:

Code:
awk 'NR==1{print "GREAT"; }NR ' file

# 3  
Old 03-11-2010
Great! Thank you it works and can you please guide me to some good SED/AWK tutorials?
# 4  
Old 03-11-2010
# 5  
Old 03-11-2010
or
Code:
sed '1i GREAT' file


cheers,
Devaraj Takhellambam
# 6  
Old 03-15-2010
MySQL

Using sed: append one line in header of the file.
See the following example:

Code:
 cat file
SOME TEXT HERE

 sed  -i  '1{s/^/GREAT\n/}' file

 cat file
GREAT
SOME TEXT HERE

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Gnu tool; sed awk echo etc to prepend or append string to a file

Looking to add text to a file, example File example; nodegroups: check-hosts: L@host.domain.com,host2.domain.com,host3.domain.com I need to take a file with a one line list of hosts separated by commas host.domain.com,host2.domain.com,host3.domain.comand prepend the string " ... (6 Replies)
Discussion started by: bash_in_my_head
6 Replies

2. Shell Programming and Scripting

Precede and Append characters using sed/awk based on a pattern

I have an input file which is similar to what I have shown below. Pattern : Data followed by two blank lines followed by data again followed by two blank lines followed by data again etc.. The first three lines after every blank line combination(2 blank lines between data) should be... (2 Replies)
Discussion started by: bikerboy
2 Replies

3. Shell Programming and Scripting

sed append to string

I am trying to replace in multiple files every instance of text that begins with http and add hyperlink characters to it. I can get it to work with the following:sed -e "s/http*.*/<a href=\"&\">&<\/a>/g" * as long as the http text is at the end of the file. I need it to stop at the end of the... (2 Replies)
Discussion started by: numele
2 Replies

4. Shell Programming and Scripting

How to append line with sed?

Input: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly Output should be: gstreamer-plugins-good gstreamer-plugins-bad gstreamer-plugins-ugly How can it be done with sed? (5 Replies)
Discussion started by: cola
5 Replies

5. Shell Programming and Scripting

sed append words

Hi all, I have a file like one two three for five six seven eight ..... Actually i need to append a label to the words that belong to the 2 column and get: one two_label three for five six_label seven eight .... I was trying with sed inside vim but I can't figure out... (9 Replies)
Discussion started by: Dedalus
9 Replies

6. Shell Programming and Scripting

sed append in first column

hi, anyone can give a sample command on sed. the text file date list belows; test.txt "a","bbb",123 "b","ccc",234 "c","eee",456 output i need to add these word "xxx" "xxx","a","bbb",123 "xxx","b","ccc",234 "xxx" ,"c","eee",456 thanks in advance, FSP (4 Replies)
Discussion started by: fspalero
4 Replies

7. Shell Programming and Scripting

How to append using sed

Hello all, I want to use sed to append a variable stored in $i, how do i do that? $i contains a path to a directory and i want to append it before the result i get from awk statement, before affecting awk results. rite now out put i get from code below is:- The path is:... (2 Replies)
Discussion started by: asirohi
2 Replies

8. Shell Programming and Scripting

SED or AWK "append line to the previous line"

Hi, How can I remove the line beak in the following case if the line begin with the special char “;”? TEXT Text;text ;text Text;text;text I want to convert the text to: Text;text;text Text;text;text I have already tried to use... (31 Replies)
Discussion started by: research3
31 Replies

9. Shell Programming and Scripting

Append lines with SED

I have the following data in a file and would like to append the lines inside each section 10, 20, 30, 40, etc... onto one line for each of the sections. Is it possible with SED to make this happen?? 10 00039393 DOCK: RECEIVE PART, TAG. D D ... (3 Replies)
Discussion started by: miklacic
3 Replies

10. Shell Programming and Scripting

append to fle using sed

Hello , I have the folloiwing command : sed -n "$var,$final w $destfile" $sourcefile where : $var - $final represent the range of line numbers to be written in $destfile However I require this command to work in a loop for which i need the sed command to keep appending the output to the... (2 Replies)
Discussion started by: shweta_d
2 Replies
Login or Register to Ask a Question