|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[SOLVED] Field $() is incorrect 'what does it mean'
I am creating (or trying to) an awk script to retrieve various data from an input file and output the data in a different format. I think it is self explanatory what I am attempting but I getting the error Field $() isincorrect when I reun it using Code:
awk -f file.awk inputfile Code:
#!/bin/awk -f
#get text between 'starting' and 'Ending'
#
BEGIN {
OFS=","
}
#'start loop here'
/Starting/,/Ending/ {
#if the line contains 'starting'
if ($0 ~ /starting/) {
day=substr($0,8,3);
month=substr($0,12,3);
date=substr($0,16,2);
sthour=substr($0,19,2);
stmin=substr($0,22,2);
stsec=substr($0,25/2);
year=substr($0,28,4);
number=substr($0,33,5);
}
#if the line contains 'LN'
if ($0 ~ /LN/) {
depot=substr($0,58,3);
order=substr($0,61,5);
}
#if the line contains 'Ending'
if ($0 ~ /Ending/) {
endhour=substr($0,19,2);
endmin=substr($0,22,2);
endsec=substr($0,25/2);
}
}
#'leave loop here'
durhour=$endhour-$sthour;
durmin=$endmin-$stmin;
dursec=$endsec-$stsec;
END {
print $year $month $date $sthour $stmin $stsec $endhour $endmin $endsec $durhour $durmin $dursec
$depot $order
}I hope someone can explain why this may be the case. Thanks in advance. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
$ does not mean 'variable' in awk. $ is an operator which means 'column'.
i.e, this: print $5 is equivalent to N=5 ; print $N If you want the value of a variable, and not the column it represents, use it without the $. |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Remove $ from variable names. Except $0, $1, etc.
|
|
#4
|
|||
|
|||
|
Thanks to you both. This resolved the issue and I understand what the error means now.
Thanks. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Solved] sort on numeric part of field | bakunin | Shell Programming and Scripting | 2 | 08-29-2012 09:00 AM |
| [Solved] Solaris 10 - Ftp Login incorrect | msarro | Solaris | 10 | 12-10-2010 02:35 PM |
| [solved] merging two files and writing to another file- solved | mlpathir | Shell Programming and Scripting | 1 | 10-07-2010 06:41 PM |
| login incorrect | espace1000 | UNIX for Dummies Questions & Answers | 2 | 08-22-2008 06:48 AM |
| Login Incorrect | sydney2008 | Red Hat | 6 | 08-22-2008 04:57 AM |
|
|