append "awk command" to the end of each line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting append "awk command" to the end of each line
# 1  
Old 11-30-2010
Data append "awk command" to the end of each line

hi;
this is my qqq.mos:
Code:
l ./gcsw 86.0.0.1 'lt all;l+;lset SectorPort=860 Tilt 861;l-'
l ./gcsw 86.0.0.2 'lt all;l+;lset SectorPort=862 Tilt 863;l-'
l ./gcsw 86.0.0.3 'lt all;l+;lset SectorPort=864 Tilt 865;l-'
...


i want to append;
Code:
l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos

to the end of each line and i want to see:
Code:
l ./gcsw 86.0.0.1 'lt all;l+;lset SectorPort=860 Tilt 861;l-;l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos'
l ./gcsw 86.0.0.2 'lt all;l+;lset SectorPort=862 Tilt 863;l-;l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos'
l ./gcsw 86.0.0.3 'lt all;l+;lset SectorPort=864 Tilt 865;l-;l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos'
...

it is hard to write to a file an awk code. i am using:
Code:
l nawk -v q="'" 'BEGIN{d="\""; printf "%s\n","l nawk "q"NR==14 && $NF!="d"Set."d"{print "d"l ./gcsw "d"r"d" "q d q d q"lt all;"d"p"d q d q d q d"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}"q" $logfile > /home/gcsw/again.mos" }' > /home/gcsw/qqq.mos

to write it in single way but donot know how to append it to the end of every line. SmilieSmilieSmilieSmilie

thanks..
# 2  
Old 11-30-2010
Code:
# cat input_file
l ./gcsw 86.0.0.1 'lt all;l+;lset SectorPort=860 Tilt 861;l-'
l ./gcsw 86.0.0.2 'lt all;l+;lset SectorPort=862 Tilt 863;l-'
l ./gcsw 86.0.0.3 'lt all;l+;lset SectorPort=864 Tilt 865;l-'
# cat awk_cmd
l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos
# awk ' NR == FNR  { str=$0;next } { print $0 ";" str } ' awk_cmd input_file
l ./gcsw 86.0.0.1 'lt all;l+;lset SectorPort=860 Tilt 861;l-';l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos
l ./gcsw 86.0.0.2 'lt all;l+;lset SectorPort=862 Tilt 863;l-';l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos
l ./gcsw 86.0.0.3 'lt all;l+;lset SectorPort=864 Tilt 865;l-';l nawk 'NR==14 && $NF!="Set."{print "l ./gcsw "r" '"'"'lt all;"p"'"'"'"} NR==5{r=$2} NR==3{p=$2 FS $3 FS $4 FS $5}' $logfile > /home/gcsw/again.mos

# 3  
Old 12-01-2010
thanks anbu23 but;

Code:
cat: cannot open awk_cmd

Smilie
# 4  
Old 12-01-2010
store the awk command in a variable and use sed as
Code:
cat input_file
l ./gcsw 86.0.0.1 'lt all;l+;lset SectorPort=860 Tilt 861;l-'
l ./gcsw 86.0.0.2 'lt all;l+;lset SectorPort=862 Tilt 863;l-'
l ./gcsw 86.0.0.3 'lt all;l+;lset SectorPort=864 Tilt 865;l-'

VAR="l nawk 'NR==14 && .."
sed "s/.*/& $VAR/g" input_file > outfile


Last edited by michaelrozar17; 12-01-2010 at 05:04 AM.. Reason: typo..
This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 12-01-2010
thx michael, it is OK Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

2. UNIX for Beginners Questions & Answers

Append content using "tee" command

Hi, How to append content into a file using tee command echo " file1 is archived"| tee -a archive.txt echo " file2 is archived"| tee -a archive.txt echo " file3 is archived"| tee -a archive.txt how to append content as new rows in the archive.txt Thanks, Srinadh. (4 Replies)
Discussion started by: srinadhreddy27
4 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

AWK for multiple line records RS="^" FS="#"

I have to pull multiple line records with ^ as the record separator(RS)... # should be my field separator (FS)... Sample record is: ^-60#ORA-00060: deadlock detected while waiting for resource ORA-00001: unique constraint (SARADM.TCKNUM_PK) violated#PROC:AVAILABLE_FOR_GETNXTTIC#02/27/2012... (7 Replies)
Discussion started by: Vidhyaprakash
7 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. 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

7. Shell Programming and Scripting

sed append "\n" to end of every line in file

I know it sounds simple, but I want to e-mail the last 6 lines of a log file, which I have tailed into logresults.txt. I'm using echo -e "Subject:server results\nFrom:server log <user@domain.com>\n"`cat logresults.txt` | sendmail -t user@domain.com which works, but the body of the e-mail has... (4 Replies)
Discussion started by: unclecameron
4 Replies

8. Shell Programming and Scripting

each line as 20digit long append zero "0" in front

i have an ip file like 121 1213412 34345353 long file want to made each line as 20digit long append zero "0" in front as 121 become 00000000000000000121 (1 Reply)
Discussion started by: RahulJoshi
1 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

10. UNIX for Dummies Questions & Answers

extran NUll character added after end of line "\n"

Hi All, I am facing a strange situation and want to find why it is occuring . When i convert the whole line into Hexadecimal character i can find the junk value after new line (\n) . If i look in binary mode it is not visible. PLease let me know how possible the junk character is added... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies
Login or Register to Ask a Question