Computing.Net > Forums > Unix > ksh, for loop, awk, Error

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ksh, for loop, awk, Error

Reply to Message Icon

Name: JoeBrewski
Date: November 25, 2008 at 02:57:15 Pacific
OS: AIX 5.3?
CPU/Ram: 16 Proc, 128GB RAM
Product: HP
Comment:

Working on a ksh script. Trying to run through a set of files, and return a set of files, which are unique subsets by column.

Code
...
__files=`ls $__PathData/*_full.txt`
echo $files

typeset -Z2 cnt=0

for fil in $__files ; do
let cnt=$cnt+1;
echo $fil;
echo $cnt;
nohup awk -F'|' '{val=$2"|"$3"|"$4; if(!(val in arr)){arr[val]=1;print val}}' $fil > $__PathData/dim_cli"$cnt.txt" &; _pid=$_pid" "$!;
done

OUTPUT on nohup:

$ more nohup.out
Tue Nov 25 05:39:35 EST 2008
...
./cdtstdload.sh[27]: 0403-057 Syntax error at line 37 : `done' is not expected.
nohup.out: END

I've tried adding semicolons among other things, same error.

Tips?

Joe

All Your Base Are Belong to Us



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 25, 2008 at 07:31:36 Pacific
Reply:

First, why don't you get the awk script working before you nohup it and create output? Get this working first:

awk -F'|' '{val=$2"|"$3"|"$4; if(!(val in arr)){arr[val]=1;print val}}' $fil

Second, your for statement will break unless $fil is always one record - no white space.

Third, what are you trying to do with the awk statement? This does not make sense to me:

if(!(val in arr)){arr[val]=1;print val

what is the significance of 'print val' and setting the array?

I think you are trying to ignore duplicates, but it doesn make any difference because the array value is always set to 1.

Fourth, how about showing a sample of your data?


0

Response Number 2
Name: JoeBrewski
Date: December 8, 2008 at 09:55:37 Pacific
Reply:

The awk did work fine, that wasn't the issue.

Tested, and the section of the line
__pid=$__pid" "$!;
was causing the error.

Broke it out into another line, and now it works fine.

Thanks

Joe

All Your Base Are Belong to Us


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: ksh, for loop, awk, Error

for loop in ssh www.computing.net/answers/unix/for-loop-in-ssh/8250.html

why isn't this for loop working?? www.computing.net/answers/unix/why-isnt-this-for-loop-working/6915.html

For Loop Iteration www.computing.net/answers/unix/for-loop-iteration/7267.html