Print between lines 7-13 who contain a certain string (awk script)
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am trying to write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.
#!/usr/bin/awk -f
BEGIN (NR>=7) && (NR<=13)
/word/ print $0
It is probably a dumb mistake on my part however I have tried searching everywhere.
the output when running
script.awk filename
is all lines that contain the word :/
awk
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
favorite
I am trying to write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.
#!/usr/bin/awk -f
BEGIN (NR>=7) && (NR<=13)
/word/ print $0
It is probably a dumb mistake on my part however I have tried searching everywhere.
the output when running
script.awk filename
is all lines that contain the word :/
awk
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.
#!/usr/bin/awk -f
BEGIN (NR>=7) && (NR<=13)
/word/ print $0
It is probably a dumb mistake on my part however I have tried searching everywhere.
the output when running
script.awk filename
is all lines that contain the word :/
awk
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I am trying to write a script (.awk) that will print out lines that contain a certain string between lines 7-13. I have it partially working however it prints out all lines that contain the string rather than only between 7-13.
#!/usr/bin/awk -f
BEGIN (NR>=7) && (NR<=13)
/word/ print $0
It is probably a dumb mistake on my part however I have tried searching everywhere.
the output when running
script.awk filename
is all lines that contain the word :/
awk
awk
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 4 mins ago


Jeff Schaller
34.6k952115
34.6k952115
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 12 mins ago


SheepWaffle
1
1
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
SheepWaffle is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:
NR >= 7 && NR <= 13 && /word/ print
($0 is the default print
argument, if none is given).
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:
NR >= 7 && NR <= 13 && /word/ print
($0 is the default print
argument, if none is given).
add a comment |Â
up vote
0
down vote
You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:
NR >= 7 && NR <= 13 && /word/ print
($0 is the default print
argument, if none is given).
add a comment |Â
up vote
0
down vote
up vote
0
down vote
You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:
NR >= 7 && NR <= 13 && /word/ print
($0 is the default print
argument, if none is given).
You've put the line restriction logic in the "BEGIN" block, which is executed before awk reads in any data. Move that logic to the main loop:
NR >= 7 && NR <= 13 && /word/ print
($0 is the default print
argument, if none is given).
answered 4 mins ago


Jeff Schaller
34.6k952115
34.6k952115
add a comment |Â
add a comment |Â
SheepWaffle is a new contributor. Be nice, and check out our Code of Conduct.
SheepWaffle is a new contributor. Be nice, and check out our Code of Conduct.
SheepWaffle is a new contributor. Be nice, and check out our Code of Conduct.
SheepWaffle is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478561%2fprint-between-lines-7-13-who-contain-a-certain-string-awk-script%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password