append each line with text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting append each line with text
# 1  
Old 03-10-2011
append each line with text

hi,

I've a file with some text in it, i need to append few strings in the beginning and end of each row.

--in file

richie
matt
..

--out file

hi, 'richie' is here
hi, 'matt' is here
...

I tried with awk command, but it fails because of '

Thanks
# 2  
Old 03-10-2011
Code:
 
awk -v a="hi," -v b="is here" '{ print a ""q$0q"" b}' q="'" input_file

# 3  
Old 03-10-2011
Code:
sed 's/^/hi\, \'/' infile | sed 's/$/\' is here/


Last edited by Franklin52; 03-10-2011 at 02:33 PM.. Reason: Please use code tags, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append text on particular line after pattern found

hi, i have /etc/inittab, I want to add another line after that when i find a pattern "l6:6:wait:/etc/rc.d/rc 6". original l6:6:wait:/etc/rc.d/rc 6 after-change l6:6:wait:/etc/rc.d/rc 6 /sbin/if-pp-to-cng (3 Replies)
Discussion started by: learnbash
3 Replies

2. Shell Programming and Scripting

find a certain line and append text to the end of the line

After I create printer queues in AIX, I have to append a filter file location within that printers custom file. within lets say test_queue.txt I need to find the row that starts with :699 and then I need to append on the end the string /usr/local/bin/k_portrait.sh. Now I've gotten the sed... (2 Replies)
Discussion started by: peachclift
2 Replies

3. Shell Programming and Scripting

Append text to end of every line

I've scoured the internet with mixed results. As an amateur I turn to the great minds here. I have a text file of 80 or so lines. I want to add ".pdf" to the end of each line. (For now that's it) Most of the internet points toward using "sed". I don't know coding but can figure things out... (4 Replies)
Discussion started by: spacebase
4 Replies

4. Shell Programming and Scripting

append text from file1 to the end of each line in file2

hi; my file2.txt:portname=1;list=10.11;l- portname=2;list=10.12;l- portname=3;list=10.13;l- ... my file1.txt:;"{'sector=%27'}"\&> so; i want to see:portname=1;list=10.11;l-;"{'sector=%27'}"\&> portname=2;list=10.12;l-;"{'sector=%27'}"\&> portname=3;list=10.13;l-;"{'sector=%27'}"\&>... (4 Replies)
Discussion started by: gc_sw
4 Replies

5. Shell Programming and Scripting

append delimeter count for each line in text file

Hi guys, plz tell me how to achieve this how to delete the lines in a file using sed command (6 Replies)
Discussion started by: hari908
6 Replies

6. Shell Programming and Scripting

Append text to end of line on all lines

Hi, I've spent some time researching for this but can't seem to find a solution. I have a file like this 1234|Test|20101111|18:00|19:00There will be multiple lines in the file with the same kind of format. For every line I need to make it this 1234|Test|20101111|18:00|19:00||create... (5 Replies)
Discussion started by: giles.cardew
5 Replies

7. Shell Programming and Scripting

How to append text to the second line of a file

Say I have a text file like: 1 3 4 How would I use ksh to put the number '2' into the second line of that file? I'm using OpenBSD so the sed syntax might be a bit different (I have no idea how to use sed, though) (4 Replies)
Discussion started by: guitarscn
4 Replies

8. UNIX for Dummies Questions & Answers

sed - append text to every line

Hi all I tried this on an old version of sed on NCR Unix MP-RAS: sed -e "s/$/nnn/" file1 >file2 This file (file1): the cat sat on the mat. the cat sat on the mat. the cat sat on the mat. becomes this (file2): the cat sat on the mat.nnn the cat sat on the mat.nnn nnn the... (3 Replies)
Discussion started by: jgrogan
3 Replies

9. Shell Programming and Scripting

Append text at end of the first line in a file

Hi I need to append some text @ end of the first line in a file. like myfile.txt list = a,b,c list.a=some.. I give the arg "d" . now it append at end of first line list=a,b,c,d list.a=some... Please help me out this (7 Replies)
Discussion started by: catgovind
7 Replies

10. UNIX for Dummies Questions & Answers

using sed to append text to the end of each line

Anyone know how to use SED to append a comma to the end of each line example: field1,field2,field3,field4 If i Cat /textfile ---- How can i append the end of /textfile with a comman? (8 Replies)
Discussion started by: Redg
8 Replies
Login or Register to Ask a Question