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
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" ) {
}
}
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