Quote:
Originally Posted by TempleStone4510!
cat tmp02.txt | awk 'BEGIN {i=(((18000*cos(-1*(atan2($11-$8,$10-$7)))+$7))); printf (" %s\n", i)}'>> tmp02.txt
|
The BEGIN block in awk gets executed before the first line of the file is read. $0 and the field variables ($1, $2, etc.) simply
don't exist at this point. Get rid of BEGIN
Code:
awk '{print $0,18000*cos(-atan2($11-$8,$10-$7))+$7}' tmp01.txt >>tmp02.txt
Quote:
I know my script is probably not efficient
|
The script definitely looks over-complicated. It would be easier, if you provided some context, a sample of input data, and explained what you're trying to achieve. Then somebody here could suggest how to improve it.
Particularly,
Code:
| tr -d '\n' | awk '{printf ("%s", $0)}'
looks redundant as
tr and
awk seem to do the same—remove newline characters.
I guess these two lines
Code:
cat tmp01.txt | tr -d '\n' | awk '{printf ("%s", $0)}'>> tmp02.txt
cat tmp02.txt | awk 'BEGIN {i=(((18000*cos(-1*(atan2(8196908-8148966,585323.3-576355.2)))+576355.2))); printf (" %s\n", i)}'>> tmp02.txt
could be replaced with one
awk expression. And using the FILENAME variable in awk could probably eliminate the two grep lines before that as well.