AWK print AWK command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK print AWK command
# 1  
Old 04-23-2012
AWK print AWK command

Code:
awk '{print "awk '{sub(/pdb_00/,"pdb_"$0"_00"); print}' pdb_"$0"_00.namd > tempo"; print "mv tempo pdb_"$0"_00.namd"}' datA2.dat > copy_script2.bash


This works when trying to print 'sed etc. etc' but if I switch to using AWK to print a set of AWK commands it doesn't work...

e.g. this WORKS:

Code:
awk '{print "sed 's/pdb_00/'pdb_"$0"_00'/g' pdb_"$0"_00.namd > tempo"; print "mv tempo pdb_"$0"_00.namd"}' dat2.dat > copy_script2.bash

Error is

Code:
line 3: syntax error at line 4: `(' unexpected

# 2  
Old 04-23-2012
Try this:

Code:
awk '{print "awk \47{sub(/pdb_00/,"pdb_"$0"_00"); print}\47 pdb_"$0"_00.namd > tempo"; print "mv tempo pdb_"$0"_00.namd"}' datA2.dat > copy_script2.bash

You need to substitute the embedded single quotes with their octal representation.
# 3  
Old 04-23-2012
It doesn't work.

Or maybe could I ask, is there a way to get sed to only substitute once (first time) instead of doing it globally?
# 4  
Old 04-24-2012
"It doesn't work"? Could you be more specific (see How to Ask Questions the Smart Way)?

Just remove the trailing g from the sed script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print only number using awk command in Linux ?

Now I'm trying summary sar data. CPU , Memory , Traffic , TPS (Min Max value) CPU is okay using below command. $ sar -p | awk '{gsub(//,"")}1' | awk 'BEGIN {min=1000000; max=0;};\ { if($7<min && $7 != "") min = $7; if($7>max && $7 != "") max = $7; } END {print min, max}' 98.93 99.55 ... (1 Reply)
Discussion started by: tom8254
1 Replies

2. Shell Programming and Scripting

Looking for an awk command to print strings only if substring is missing

I have a file that I need to find each interface that has move-group on the interface line and print this line if the lines under the interface does Not have "filter-shared 14". Example file: interface 1/1/1/0 move-group decription one one one zero no shut filter-shared 14... (21 Replies)
Discussion started by: numele
21 Replies

3. Shell Programming and Scripting

Combining awk printf and print strftime command

I have a lines like below, captured from rrdtool fetch command, 1395295200 2.0629986254e+06 7.4634784967e+05 1395297000 2.0198121616e+06 6.8658888903e+05 1395298800 1.8787141122e+06 6.7482866452e+05 1395300600 1.7586118678e+06 6.7867977653e+05 1395302400 1.8222762151e+06 7.1301678859e+05I'm... (3 Replies)
Discussion started by: rk4k
3 Replies

4. Shell Programming and Scripting

awk command for complex search and print

Input: 9999~cbc~100~209~ozzxczcz~10001001001~100~abc10 123~a~sdklfjl~sldoi~~~ksjdfnkjsdf~123456 125~g~sdklfjl~slsdfsdfsdfsdfdoi~~~~~~~~ksjdfnkjsdf~345 127~wera~sdklfjl~sldoi~~~ksjdfnkjsdf~123 128~awer~swerwerdklfjl~sldoi~~~ksjdfnkjsf~1da2345... (7 Replies)
Discussion started by: onesuri
7 Replies

5. Shell Programming and Scripting

Display Additional Variable string in awk print command

Hi all, I have script to monitor and sum up the total memory use up for each individual process. proc=$1 svmon -P -O summary=basic,unit=MB|awk 'NR>4'|grep -w "${proc}" |awk '{sum+=$3} END {printf "\t" sum """\n";}' But I would like the script to be able to display as following ... (3 Replies)
Discussion started by: ckwan
3 Replies

6. Shell Programming and Scripting

print command in awk

Hi can print command in awk take the variable and write its value in the file? Excerpt from my shell script. for some reason, $proc is being written in the file instead of its value. can someone tell me what is the issue? for proc in EH LOGEV do echo $proc ./plist -P $proc |... (2 Replies)
Discussion started by: lookinginfo
2 Replies

7. Shell Programming and Scripting

awk command to print multiple columns

Hello Team, I have written following command which is giving output is as shown below. bash-3.00$ grep -i startup catalina.out | tail +2 | sed -n 1p | awk -F" " '{ for (x=1; x<=5; x++) { printf"%s\n", $x } }' Dec 19, 2010 3:28:39 PM bash-3.00$ I would like to modify above command to... (2 Replies)
Discussion started by: coolguyamy
2 Replies

8. Shell Programming and Scripting

awk command : To print the output to a file

half of the problem is already solved with the help of bartus11 suggestion I have a txt file having rows and coulmns, i want to perform some operation on a specific coulmn starting from a specific line. 50.000000 1 1 1 1000.00000 1000.00000 ... (5 Replies)
Discussion started by: shashi792
5 Replies

9. UNIX for Advanced & Expert Users

Awk command to print the field

894344202808090;11122;040320 075858 166;101;0;0;10u;0;NA;65;221890;2;101973;185059;568674;Y; PRE;0;0;NA;NA;0;NA;0;NA;textmsg;textmsg_snd1;telusmob;TEXTMSG1;0.15000000;126037;2010/03/04 12:58:57gmt;0;70532192; plz tell me any awk command which on the basis of the yellow field which is... (1 Reply)
Discussion started by: madfox
1 Replies

10. Shell Programming and Scripting

awk field separator or print command

Hello Experts, I am back, with another doubt. I am not sure what it relates to this time - awk or the print command actually. I'll explain the scenario: I have a huge file, and it has some traces(logs). In between those logs, there are statements with some SQL queries. All I want to do is... (4 Replies)
Discussion started by: hkansal
4 Replies
Login or Register to Ask a Question