Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with passing variables

Status
Not open for further replies.

Meher1

Programmer
Jun 4, 2003
7
US
Hi. I was wondering if I could fix the problem I have with my previous message in a different way. I'm sorry for multiple threads, I'm a newbie to both unix and awk and do not even have a awk book to refer.

I'll repeat the whole issue again.

********************************************************
test.ksh

for i in $dir
do
test.awk i > $dir/(basename i)_C
done

**********
test1.awk

BEGIN{OFS=FS="*"}
/QR/{
for (j=1;j<=NF-7;j++) {
if ($j ~ /QR/ && $(j+1)==&quot;XA&quot;) sub(/Z/,&quot;K&quot;,$(j+7))
print $0
}
}

*****************************************************
In test.ksh where it is printing the out put, if the if condition satisfies, then only I want to create a file *_C, if it does not I don't want the file created. The above script is creating a *_C file for all the files in directory $dir.


I was wondering if I could print a file in /dir with filename (what ever the file name is, if its is X, the out put file should be X_C) *_C with in the awk script itself.

TIA.
 
Do all the lines in the file you want to change have QR in them? If so, something like this might do what you want.

awk -f test1.awk $dir/*

BEGIN{OFS=FS=&quot;*&quot;}
/QR/{
for (j=1;j<=NF-7;j++) {
if ($j ~ /QR/ && $(j+1)==&quot;XA&quot;) {
sub(/Z/,&quot;K&quot;,$(j+7))
print $0 > FILENAME &quot;_C&quot;
}
}
}

Also, It's not clear to me how you are executing awk. Does you script have a line like #!/bin/awk in it? And what operating system are you on?

CaKiwi

&quot;I love mankind, it's people I can't stand&quot; - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top