Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

works on command line but doesnt work in file?

Status
Not open for further replies.

jonnyc2

Programmer
Apr 4, 2006
7
GB
I'm new to awk but I'm stuck!! I'm finding it real hard!

so this works fine on the command line:

awk 'BEGIN { RS = "__+" } /string/' /blah/blah/blah/blah/blah/myfile

but when I put it into a file like this:

#!/usr/bin/awk

BEGIN { RS = "__+" } /string/ "/blah/blah/blah/blah/blah/myfile"

I get this (I've tried unquoting the file path):

wk: cmd. line:1: ./printfile
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: ./printfile
awk: cmd. line:1: ^ unterminated regexp

also ideally I want my RS to be say 100 x "_"
is there a way to do this in awk like you can in perl?

I can get this to work:

BEGIN {
while ( getline < "/blah/blah/blah/blah/blah/myfile" ) {

print
}
}

but then how can I only print sections containing my regex?

what I eventually want to do is use the elements of my ARGV array as my regex, something like this: /ARGV[1]|ARGV[2]/ etc...

cheers




 
Contents of printfile.awk:
#!/usr/bin/awk
BEGIN { RS = "_{100}" }
/string/

How to call it:
./printfile.awk /blah/blah/blah/blah/blah/myfile


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
OOps, sorry for the typo:
Contents of printfile.awk:
#!/usr/bin/awk [!]-f[/!]
BEGIN { RS = "_{100}" }
/string/

How to call it:
./printfile.awk /blah/blah/blah/blah/blah/myfile


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

thanks for that but I cant get it to work, it just prints the whole record and doesn't recognise the _{100}.
 
Code:
Contents of printfile.awk:
#!/usr/bin/gawk --re-interval -f
BEGIN { RS = "_{100}" }
/string/

Make sure to use gawk.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top