user3299512
user3299512

Reputation:

Fitting in this awk statement

I have a bash script I am working on that calls another awk script. This is the line of code:

awk -f /home/rkahil/BMS/parse.awk $filename.tmp > $filename | /..,[A-Z][A-Z]/ $filename

I know syntactically this is worng, but I need this following regex expression /..,[A-Z][A-Z]/ $filename is syntactically wrong but I need to fit this in to this statement and am not quite sure how to. Does anyone have any suggestions?

Upvotes: 0

Views: 75

Answers (3)

glenn jackman
glenn jackman

Reputation: 247042

I'm assuming you need to add the last regex to the awk script without modifying the awk script. You need to edit your question and provide a clear statement of your requirements. See https://stackoverflow.com/help/asking

This may be a GNU awk feature, but you can provide multiple -f options that concatenates all the named awk script into one. Thus:

awk -f /home/rkahil/BMS/parse.awk \
    -f <(echo 'FILENAME ~ /..,[A-Z][A-Z]/') \
    $filename.tmp > $filename

Demo:

$ cat foo.awk
/foo/ {print}
$ cat bar.awk 
/bar/ {print}
$ awk -f foo.awk -f bar.awk -f <(echo '/baz/ {print}') <<END
blah
foo
hello
world 
var bar car
1234
ab cbazdef
bye
END
foo
var bar car
ab cbazdef

Upvotes: 1

kojiro
kojiro

Reputation: 77147

Perhaps you mean:

awk -f /home/rkahil/BMS/parse.awk "$filename.tmp" | grep '..,[A-Z][A-Z]' > "$filename"

? It's not entirely clear what you mean, but the above will perform the awk script without modification, and then filter the output on the given regular expression, finally writing the result to the original file.

Upvotes: 0

anubhava
anubhava

Reputation: 785651

You can include this condition in your awk script:

awk 'FILENAME ~ /..,[A-Z][A-Z]/{...}' "$filename"

Upvotes: 0

Related Questions