Script To Continue To The Next
File
I have several files to run this through I notice that when I use For it crashes. DIRS = "at_1 be_1 ch_1"
Does not like ${j}_main.txt in the script- will not go pass this line-- everything from there on is not parsed right or something The original script works fine on one file but I need to run it on multiple files. gawk -F\| 'BEGIN {
{w2=sprintf("%2.2d",$2)
How do I use the above script to continue to the next file once it has finished the first file? The gawk's option --assign might be helpful : bash/ksh/sh paramater substitution
' - no shell $x substitution
Variable assignment in most shells is without spaces
around the equal-sign:
There are several ways to feed a shell variable into awk. One way is: while ((getline < "'${j}'_main.txt") > 0) It appears that we are enclosing ${j} within single quotes, but in fact we are placing it OUTSIDE of the single-quoted awk program, thus allowing the shell to evaluate it on the command line before awk executes. If we look at the big picture all on a single line: awk 'some code'${j}'some more code' new.txt Then you can see that we have a single quoted string followed by ${j} followed by another single quoted string. But your for-loop is not going to do what you want. It will run awk 3 times, and each time awk will read new.txt and will create new.modified, each time replacing the previous new.modified. The new.modified that you end up with will be the one processed on the 3rd for-loop with ch_1_main.txt. Making awk append each time to new.modified (>> new.modified) will just give you a new.modified that has 3 copies of new.txt in it, one copy processed with at_1_main.txt etc. I think you are wanting new.txt to be processed once, pulling conversion info from all main.txt's, correct? If so, one way would be: rm -f combined_main.txt 2> /dev/null
gawk -F\| 'BEGIN {
And if you do not want to create a temporary combined main.txt, it could be coded so that awk reads all main.txt's individually.
Have a Unix Problem
Unix Books :-
Return to : - Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|