Awk error -- awk: 0602-562 Field $() is not correct.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk error -- awk: 0602-562 Field $() is not correct.
# 1  
Old 01-22-2010
Awk error -- awk: 0602-562 Field $() is not correct.

Code:
typeset -i i=1
while read -r filename; do

Splitfile=`$Targetfile_$i.txt`
awk 'substr($0,1,5) == substr($filename,1,5) && substr($0,526,2) == substr($filename,6,2) && substr($0,750,12) == substr($filename,8,12)' $SourceFilename >> $Splitfile
i=i+1
done < /tmp/list.out

I am using this logic to compare the positions and outputting the file based on that

I am getting the following awk error when executing it


awk: 0602-562 Field $() is not correct.


Help will be appreciated

Last edited by pludi; 01-22-2010 at 02:32 AM.. Reason: code tags, please...
# 2  
Old 01-22-2010
To use a shell variabele with awk you should do something like this:

Code:
awk -v fn="$filename" 'substr($0,1,5) == substr(fn,1,5).....'

Have a read of:

Using Shell Variables - The GNU Awk User's Guide
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problem with getting awk to multiply a field by a value set based on condition of another field

Hi, So awk is driving me crazy on this one. I have searched everywhere and read man, docs and every related post Google can find and still no luck. The actual files I need to run this on are sensitive in nature, but it is the same thing as if I needed to calculate weighted grades for multiple... (15 Replies)
Discussion started by: cotilloe
15 Replies

2. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk to adjust coordinates in field based on sequential numbers in another field

I am trying to output a tab-delimited result that uses the data from a tab-delimited file to combine and subtract specific lines. If $4 matches in each line then the first matching sequential $6 value is added to $2, unless the value is 1, then the original $2 is used (like in the case of line... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

Pass awk field to a command line executed within awk

Hi, I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date). All my attempts failed this far. Here's an example. It works fine with timestamp hard-codded into the command echo "1381653229 something" |awk 'BEGIN{cmd="date -d... (4 Replies)
Discussion started by: tuxer
4 Replies

5. Shell Programming and Scripting

Help to get correct data using awk

I have this input.|user1 |10.10.10.10 |23|046|1726 (212) |0 |user2 |10.10.10.11 |23|046|43 (17) |0 |test |10.10.10.12 |23|046|45 (10) |0 |test1 |10.10.10.13 |23|046|89 (32) |0 I need to get the data for a user like thisuser1 1726 user2 43 test 45 test1 89... (11 Replies)
Discussion started by: Jotne
11 Replies

6. Shell Programming and Scripting

Error awk: 0602-592 cannot contain a newline character

Hi guys, I'am new at this forum as well as with unix. currently iam trying to create a unix script that will write certain string of words into a file depending on certain conditions apparently i am having problems in terms of writing into the file using the awk. it returns an error ... (0 Replies)
Discussion started by: jihmantiquilla
0 Replies

7. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

8. Shell Programming and Scripting

Awk Script Counting of Correct vs. Error Responses

Hello, I have been trying to use an awk script to parse out correct and incorrect answers in a simple tab-delimited text file. I am trying to compare the user's response to the stimulus presented (in this case, an arrow pointing left or right; e.g., "<--" vs. "-->"). I have the data for the... (6 Replies)
Discussion started by: Jahn
6 Replies

9. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

10. Shell Programming and Scripting

Error : Field $() is not correct

Hi All, I'm new to shell scripting. Trying to extract substring using awk script as shown below : Flag=$1 Length=`echo ${#Flag}` NewLen=$Length-2 NewFlag=`echo $Flag|awk '{print substr($Flag,0,$NewLen)}'` echo "New string is : $NewFlag" exit When I execute this script the following... (3 Replies)
Discussion started by: abbey
3 Replies
Login or Register to Ask a Question