inserting characters before each line...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting inserting characters before each line...
# 1  
Old 09-01-2004
inserting characters before each line...

Hi ,

the fog is fulling my brain after holidays , somebody can help me ?

I have a file in input like that :

toto
tata
tutu

and trying with awk to insert the compete file string as :

/dir1/dir2/toto
/dir1/dir2/tata
/dir1/dir2/tutu

i used to write :
awk 'BEGIN {FS="\\"} {print "/dir1/dir2"/"$3}'
where i needed field number 3 in the line but here i got no separator , i tried directly $0 or $1 but it fails.
Normally it would be easier !!!

Thanks in advance

Christian
# 2  
Old 09-01-2004
awk '{ print "/dir1/dir2/"$0 }' file > newfile

Cheers
ZB
# 3  
Old 09-01-2004
Thanks ,

well i used that and it works but in fact it's a little more complicated , i use another variable $REP :

awk '{ print "/dir1/dir2/"$REP"/"$0 }' file > newfile

and it fails with :

awk: Field $() is not correct.

The input line number is 1.
The source line number is 1.

the system doesn't understand the variable $REP

regards
christian
# 4  
Old 09-01-2004
You can assign the variable when you invoke awk, e.g.

Code:
REP=foo
awk -v rep=$REP '{ print "/dir1/dir2/"rep"/"$0 }' file > newfile

Cheers
ZB
# 5  
Old 09-02-2004
Thanks for your help , just what i needed !!

Christian
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Inserting n characters to beginning of line if match

I would like to insert n number of characters at the beginning of each line that starts with a given character. If possible, I would be most appreciative for a sed or awk solution. Given the data below, I would like to be able to insert either 125 spaces or 125 "-" at the beginning of every line... (6 Replies)
Discussion started by: jvoot
6 Replies

2. UNIX for Dummies Questions & Answers

Inserting new line

Hi all, I want ot print a header with new line in the end. I am using echo like echo "this is header" I want output like This is header $ I tried -e also but it's not working. echo - e Can anyone help please? (6 Replies)
Discussion started by: dsa
6 Replies

3. Shell Programming and Scripting

Commenting a specific line and inserting a new line after commented line.

Hello All, I have following file contents cat file #line=aaaaaa #line=bbbbbb #line=cccccc #line=dddddd line=eeeeee #comment=11111 #comment=22222 #comment=33333 #comment=44444 comment=55555 Testing script Good Luck! I would like to comment line line=eeeeee and insert a new line... (19 Replies)
Discussion started by: manishdivs
19 Replies

4. UNIX for Dummies Questions & Answers

inserting characters based on condition

hi i have a file that contains the data like this 12345 12453 8990998987 0989876656 12345678 12344 133678999 12345677 i should insert "+" and "-" signs for each line i,e., + 12345 - 12453 + 8990998987 - 0989876656 + 12345678 - 12344 (2 Replies)
Discussion started by: anurupa777
2 Replies

5. Shell Programming and Scripting

Inserting a line in a file after every alternate line

Friends , I have a large file and i need to insert a line after every line.I am actually unaware how to do it.Any help appreciated. My File control station *ATM* , qread $OSS.Jul13A.FI01 interval 1 intcount 1 control station *ATM* , qread $OSS.Jul13A.FI02 interval 1 intcount... (4 Replies)
Discussion started by: appu2176
4 Replies

6. UNIX for Dummies Questions & Answers

Inserting control characters at the end of each line

How to add control characters at the end of each line in a file? Can anyone help me with this? Thanks, Shobana (2 Replies)
Discussion started by: Shobana_s
2 Replies

7. UNIX for Advanced & Expert Users

Inserting a line before the line which matches the patter

Hi Is there any command where we can insert a line "2|||" before every line starting with "3|" my input is as follows 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 3|79.58|||GBP|| 1|ETG|12345 2|EN_GB||Electrogalvanize 0.5 m2 ( Renault ) 1|ETG|12345 3|88.51|||GBP|| desired output... (10 Replies)
Discussion started by: laxmi131
10 Replies

8. Shell Programming and Scripting

Inserting a new line

I have a file where each line starts with a "update" statement. I want to insert a new line, after each line, with the words "go" in the new line. Can someone help me out with this? (1 Reply)
Discussion started by: ssmallya
1 Replies

9. UNIX for Dummies Questions & Answers

inserting line??

guys can anyone tel me how to insert a line in a file(bash) using line number i wanna insert the line using LINE NUMBER...i know for inserting above or below a perticular line we can use sed a\ or i\.... thanks in advance.... (7 Replies)
Discussion started by: anj
7 Replies

10. Shell Programming and Scripting

vi : inserting non-printing characters

I am trying to edit a syslinux msg file. I want to precede color codes with control characters. I have tried insert mode, then control v followed by the color code; however, I continue to get " [O " if I type the color code or enter ESC mode. How can I just insert say " ^L " ? (2 Replies)
Discussion started by: cstovall
2 Replies
Login or Register to Ask a Question