awk to find the multiple pattern in a line
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
Example :-
File1.txt
Type header call_header
abc , def , ghi ,
jkl ,mno
END
Define call_header
type as call_header
Fil2.txt
Type head call_header
data1, data2, voice ,
mms , mms2
END
Define call_header
type as call_header
I have tried:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
However, it is printing other lines also .
Need Below data only :
Type header call_header
abc , def , ghi ,
jkl ,mno
END
shell-script text-processing awk
add a comment |Â
up vote
1
down vote
favorite
I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
Example :-
File1.txt
Type header call_header
abc , def , ghi ,
jkl ,mno
END
Define call_header
type as call_header
Fil2.txt
Type head call_header
data1, data2, voice ,
mms , mms2
END
Define call_header
type as call_header
I have tried:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
However, it is printing other lines also .
Need Below data only :
Type header call_header
abc , def , ghi ,
jkl ,mno
END
shell-script text-processing awk
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
Example :-
File1.txt
Type header call_header
abc , def , ghi ,
jkl ,mno
END
Define call_header
type as call_header
Fil2.txt
Type head call_header
data1, data2, voice ,
mms , mms2
END
Define call_header
type as call_header
I have tried:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
However, it is printing other lines also .
Need Below data only :
Type header call_header
abc , def , ghi ,
jkl ,mno
END
shell-script text-processing awk
I have file file1.txt /file2.txt When I run the awk command with boundary search between "Type header call_header " and "END" it print the lines below END also .
Example :-
File1.txt
Type header call_header
abc , def , ghi ,
jkl ,mno
END
Define call_header
type as call_header
Fil2.txt
Type head call_header
data1, data2, voice ,
mms , mms2
END
Define call_header
type as call_header
I have tried:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
However, it is printing other lines also .
Need Below data only :
Type header call_header
abc , def , ghi ,
jkl ,mno
END
shell-script text-processing awk
edited Jan 22 at 18:56
Kusalananda
103k13202319
103k13202319
asked Jan 22 at 18:46
isha
113
113
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
Your awk
invocation is incorrect:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
Here, awk
would search for a file called print
.
The whole script should be within the single quotes:
awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt
Or, alternatively (shortening the first regular expression slightly and getting rid of print
completely),
awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt
Tested with OpenBSD awk
, mawk
and GNU awk
.
With sed
, this is remarkably similar to the above:
sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Your awk
invocation is incorrect:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
Here, awk
would search for a file called print
.
The whole script should be within the single quotes:
awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt
Or, alternatively (shortening the first regular expression slightly and getting rid of print
completely),
awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt
Tested with OpenBSD awk
, mawk
and GNU awk
.
With sed
, this is remarkably similar to the above:
sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt
add a comment |Â
up vote
2
down vote
Your awk
invocation is incorrect:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
Here, awk
would search for a file called print
.
The whole script should be within the single quotes:
awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt
Or, alternatively (shortening the first regular expression slightly and getting rid of print
completely),
awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt
Tested with OpenBSD awk
, mawk
and GNU awk
.
With sed
, this is remarkably similar to the above:
sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Your awk
invocation is incorrect:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
Here, awk
would search for a file called print
.
The whole script should be within the single quotes:
awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt
Or, alternatively (shortening the first regular expression slightly and getting rid of print
completely),
awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt
Tested with OpenBSD awk
, mawk
and GNU awk
.
With sed
, this is remarkably similar to the above:
sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt
Your awk
invocation is incorrect:
awk '/^Type (header|head) call_header$/,/^END?$/' print file1.txt
Here, awk
would search for a file called print
.
The whole script should be within the single quotes:
awk '/^Type (header|head) call_header$/,/^END?$/ print' file1.txt
Or, alternatively (shortening the first regular expression slightly and getting rid of print
completely),
awk '/^Type head(er)? call_header$/,/^END?$/' file1.txt
Tested with OpenBSD awk
, mawk
and GNU awk
.
With sed
, this is remarkably similar to the above:
sed -nr '/^Type head(er)? call_header$/,/^END?$/p' file1.txt
answered Jan 22 at 18:52
Kusalananda
103k13202319
103k13202319
add a comment |Â
add a comment |Â
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%2f418923%2fawk-to-find-the-multiple-pattern-in-a-line%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