Visit The New, Modern Unix Linux Community


AWK syntax /bailing script error when executing in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK syntax /bailing script error when executing in UNIX
# 1  
MySQL AWK syntax /bailing script error when executing in UNIX

Hi I am trying to execute the following awk script in unix but getting
the following error

awk: syntax error near line 1
awk: bailing out near line 1
Code:
for i in `cat search`
 do
   grep -i -l $i *.sas | awk -v token=$i '{print token "\t" $0}'
 done

Please let me know what could be the reason.
And this is to pass some tokens and search in a directory to find particular tokens.

Last edited by Franklin52; 03-04-2011 at 03:00 AM.. Reason: Please use code tags
# 2  
You get a useless use of cat award. Smilie

You also need to quote things more, probably $i is being split into two strings and awk is trying to use the second half of it as its script.

Code:
while read TOKEN
do
        grep -i -l "$i" *.sas | awk -v token="$i" '{print token "\t" $0}'
done < search

# 3  
not working

well!!! the same code I have been using since long time...and it never showed this error....I am executing this on diff flavour of unix.....let me know any other way

---------- Post updated at 12:01 PM ---------- Previous update was at 11:58 AM ----------

Quote:
Originally Posted by Corona688
You get a useless use of cat award. Smilie

You also need to quote things more, probably $i is being split into two strings and awk is trying to use the second half of it as its script.

Code:
while read TOKEN
do
        grep -i -l "$i" *.sas | awk -v token="$i" '{print token "\t" $0}'
done < search



cat > abc
for i in `cat tks`
do
grep -i -l $i *.txt | awk -v token=$i '{print token "\t" $0}'
done

Control-D

cat > tks
India Australia America

Control-D

cat -> file1.txt

India and Australia are world champions in cricket

Control-D

cat -> file2.txt

America is NBA champion.

Control-D
Now all files created
at the unix prompt where you run all these files

sh abc
# 4  
Quote:
Originally Posted by nandugo1
well!!! the same code I have been using since long time...and it never showed this error....
I'm reminded of something from space history... On opening an electronic module for inspection: "My god, this part passed all our tests and it's *garbage*!" Just because it works doesn't mean it's sensible. And if you use "for stuff in `cat file`" all over the place? You've suddenly got something to worry about.

The error's always been possible, but somehow you've never fed it lines with spaces before, and never fed it files larger than you can squeeze into a variable. You've been lucky.

Because $i wasn't quoted, your awk line ends up awk -v token=India and Australia are world champions in cricket '{print token "\t" $0}' token gets the "india" part. The rest of it -- "and", "australia", "are", "world", "champions", "in", and "cricket" -- awk tries to run as scripts or read as files.
Quote:
I am executing this on diff flavour of unix.....let me know any other way
I just did. Try it, it should work. It should be able to handle files of any size too, where your version will barf on files bigger than a few kilobytes on some systems.

Last edited by Corona688; 03-03-2011 at 01:55 PM..
# 5  
Please provide the sample of search file and *.sas file, and also the expect O/P.

Now I have to guess, seems your system is solaris. need nawk.

all in one awk:

Code:
nawk 'NR==FNR{a[NR]=tolower($0);next}{ for ( i in a) {if (tolower($0) ~ a[i]) print a[i],$0}}' OFS="\t" search *.sas


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #188
Difficulty: Easy
Python is an interpreted, high-level, general-purpose programming language, created by Linus Torvalds and first released in 1991
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Isql and If Exist syntax error in UNIX script

Hello Everyone, Coming again for your help to solve the below error: In a script, i had created a temp table (Temp_table) and loaded the data in it using bcp command (performed successfully) and I wanted to move it to the preferred table (called Main_table) for further use. hence I have added... (7 Replies)
Discussion started by: Suresh
7 Replies

2. Shell Programming and Scripting

Isql syntax error in UNIX script

Hello Everyone, Coming again for your help to solve the below error: In a script, i had created a temp table (Temp_table) and loaded the data in it using bcp command (performed successfully) and I wanted to move it to the preferred table (called Main_table) for further use. hence I have added... (1 Reply)
Discussion started by: Suresh
1 Replies

3. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies

4. Shell Programming and Scripting

Syntax Error in Unix Shell Script

I am trying to run a unix script in my home directory.Snippet below echo "`date '+%Y%m%d_%H%M%S'` Getting ProductList.dat" if ( -f $DIR/ProductList.dat) then cp $DIR/ProductList.dat MigratedProductList.dat else echo "`date '+%Y%m%d_%H%M%S'`ProductList.dat does not exist; Processing... (4 Replies)
Discussion started by: Mary James
4 Replies

5. Answers to Frequently Asked Questions

awk: bailing out

If you see this: awk: syntax error near line 1 awk: bailing out near line 1 Chances are you are working on Solaris and you are using standard awk. If so, you need to use /usr/xpg4/bin/awk instead, which is POSIX awk (or nawk if that is not available). (1 Reply)
Discussion started by: Scrutinizer
1 Replies

6. Shell Programming and Scripting

Awk and read bailing out

Hi All, Can some body help me in this to work #!/bin/ksh nof=`wc -l outFile_R.out | sed -e 's/*//g' ` no_of_lines=`expr $nof - 0` z=1 while ] do cat outFile_R.out | awk -v I="$z" 'NR==I { print $0 }' | read from_date to_date id echo "executing $from_date... (2 Replies)
Discussion started by: sol_nov
2 Replies

7. Shell Programming and Scripting

How to Check Shell script syntax w/o executing

Hello All, I looking for a way to verify the correction of shell script syntax. Is there any switch like -c in perl which do this in shell ? Thank You. (1 Reply)
Discussion started by: Alalush
1 Replies

8. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

9. Shell Programming and Scripting

awk syntax error

mVar=0 count=`awk -F, '( ( $2 ~ /^GIVEUP$/ && $3 ~ /^NEW$/ ) || ( $2 ~ /^SPLIT$/ && $3 ~ /^NEW$/ ) || ( $2 ~ /^OPTION$/ && $3 ~ /^NEW$/ ) || ( $2 ~ /^OPTIONSPLIT$/ && $3 ~ /^NEW$/ ) ) { count++ } END { print count }' myCSV.csv myVar=`expr $myVar + $count` Can I do this? I get a syntax... (4 Replies)
Discussion started by: yongho
4 Replies

10. Shell Programming and Scripting

-awk: bailing out near line 1

Hi I'm using cygwin and the script below works just fine under cygwin.. when i upload it on a unix server the script fails with the following errors -awk: syntax error near line 1 -awk: bailing out near line 1 any ideas why? thanx awk '($2 ~ /*/) { if ($4 < 40){ print... (3 Replies)
Discussion started by: kion
3 Replies

Featured Tech Videos