Issues with AWK


 
Thread Tools Search this Thread
Operating Systems AIX Issues with AWK
# 1  
Old 05-06-2009
Issues with AWK

Hi there
I have written a ksh script on a Red Hat OS and the following extract works.
awk '{if (NR != 1) {print $rec1_field }}' $file1 >> combined

When I run the same script on an AIX OS, I get the following error.

awk: 0602-562 Field $() is not correct.
The input line number is 2. The file is LetterWriting_Type_EPRO.csv.
The source line number is 1.

It would appear that I need to assign the script variable $rec1_field.

Can anyone advise

Thanks
Alan
# 2  
Old 05-06-2009
$rec1_field is not an awk variable. to pass shell variable to awk, use -v option
# 3  
Old 05-06-2009
Thanks for your prompt reply.

Your advice has fix one problem, but raised another. The variable $rec1_field, actually contains $1,$2,$3 etc, in other words it contains the format required to produce a desired result. When I use the -v option
awk -v awkvar=$new_rec1_field '{if ( NR != 1 ) { print $awkvar }}' $file1 >> combined

awk displays and error stating it can't parse $($1,$2,$3 etc

Any more switches you can turn on for me.

Thanks

Alan
# 4  
Old 05-06-2009
print awkvar, not $awkvar
# 5  
Old 05-06-2009
Sorry I tried that.

Instead of getting the field information printed, I get $1,$2,$3..... etc printed. That is variable $1 is not being replaced by the first field in the file $file1
# 6  
Old 05-06-2009
What is your exact requirement? What does the variable new_rec1_field hold? If it is refering to fields -$1, $2 etc. why can't it be directly use inside awk?



cheers,
Devaraj Takhellambam
# 7  
Old 05-06-2009
I have written a script that combines several files that contains both similar and dissimilar fields within each record. The resultant file needs to be a concatenation of all files vertically, not horizontally (ie can't use cat). Can't use join as any common field can only be displayed once in the resultant file.
So I created a variable "$rec1_field" that contains the order of the variables I need to be output for each record, as parsed by awk.
The variable literally contains "$1,$2,$3,....". What I thought I could do ,is replace {print $1} within awk with {print $rec1_field}, and let awk expand the variable to $1,$2,etc.

I developed the script on a Linus Red Hat platform and it works 100%, but when I run it under AIX it fails. See previous posts.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues with executing awk

I am piping some output to awk and would like to print fields $1 $2 and $3 $4 only if they exist. Note the awk begins with awk '{print $NF " " since I want the last field printed first. (7 Replies)
Discussion started by: motdman
7 Replies

2. Shell Programming and Scripting

Issues in reading file using 'awk'

Dear all, I am using following function of some script to assign variable "JobNo" some value form file $SAMPLE"_status.log" ( generated using the red color command ) crab ntuplize_crab -status -c $SAMPLE >& $SAMPLE"_status.log" & echo $SAMPLE"_status.log" "=====" jobNo=$(awk... (10 Replies)
Discussion started by: emily
10 Replies

3. Shell Programming and Scripting

Issues with awk and tcsh

Hello experts, I have two files which I'm uploading. One is an awk script and other file acts as an input to the script via positional parameter. awk -f intlmenu.awk jobsq.txt This run fine in C shell on SCO OpenServer Release 5.0.7. When I run it on Solaris 10 ( tcsh shell ) I get... (2 Replies)
Discussion started by: maverick_here
2 Replies

4. Shell Programming and Scripting

Awk OFS issues

Hi, Could anyone tell me what Im doing wrong here any help will be much appreciated #!/bin/bash ls -ltr /export/home/tjmoore > /export/home/tjmoore/log100 awk -F " " /export/home/tjmoore/log100 'BEGIN {OFS="\t";} {print $1,$2,$3,$4,$5, $6,$7,$8,$9;}' > /export/home/tjmoore/log1001 I... (9 Replies)
Discussion started by: 02JayJay02
9 Replies

5. Shell Programming and Scripting

Awk OFS issues

Hi Im trying to tidy up the output of a who command when it writes to a log, everything I've tried doesnt seem to work though, any help would be massively appreciated. Im using the awk command to set the OFS as tab. #!/bin/bash who >> /export/home/tjmoore/logusers awk -F 'BEGIN... (3 Replies)
Discussion started by: 02JayJay02
3 Replies

6. Shell Programming and Scripting

Issues running an awk script

Hi, I have an awk script(test.awk) as below which I am trying to execute through the following command and I am getting error as follows. Request your valid inputs on where I am going wrong. Thanks. :/usr/chandra# awk -f test.awk input.txt syntax error The source line is 1. The error... (18 Replies)
Discussion started by: adept
18 Replies

7. UNIX for Dummies Questions & Answers

awk: issues for writing a script

%%%%% (7 Replies)
Discussion started by: lucasvs
7 Replies

8. Shell Programming and Scripting

Filtering Issues Using sed and awk

Hi, I am currently using the sed and awk commands to filter a file that has multiple sets of data in different columns. An example of part of the file i am filtering is as follows; Sat Oct 2 07:42:45 2010 01:33:46 R1_CAR_12.34 Sun Oct 3 13:09:53 2010 00:02:34 R2_BUS_56.78 Sun... (4 Replies)
Discussion started by: crunchie
4 Replies

9. UNIX for Dummies Questions & Answers

Awk Performance Issues

Hi All, I'm facing an issue in my awk script. The script is processing a large text file having the details of a number of persons, each person's details being written from 100 to 250 tags as given below: 100 START| 101klklk| ... 245 opr| 246 55| 250 END| 100 START| ... 245 pp| 246... (4 Replies)
Discussion started by: pgp_acc1
4 Replies

10. Shell Programming and Scripting

Awk output issues.

I have the follwing code: awk '{print $1}' HITS #Searches HITS file column one. Column one is filenames awk '{print $2}' HITS | sort -n | wc -l #Searches HITS file and sorts numerically and outputs line count. column 2 is IP addresses awk... (4 Replies)
Discussion started by: amatuer_lee_3
4 Replies
Login or Register to Ask a Question