print lines with unique specified fields
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
How to print lines based on having unique fields 2
, 3
and 4
?
fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.
Input:
10,11,12,A,3
10,11,12,A,4
10,11,12,B,3
OUTPUT:
10,11,12,B,3
text-processing awk uniq
add a comment |Â
up vote
-1
down vote
favorite
How to print lines based on having unique fields 2
, 3
and 4
?
fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.
Input:
10,11,12,A,3
10,11,12,A,4
10,11,12,B,3
OUTPUT:
10,11,12,B,3
text-processing awk uniq
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
How to print lines based on having unique fields 2
, 3
and 4
?
fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.
Input:
10,11,12,A,3
10,11,12,A,4
10,11,12,B,3
OUTPUT:
10,11,12,B,3
text-processing awk uniq
How to print lines based on having unique fields 2
, 3
and 4
?
fields number 2 and 3 are numbers and field three is alphabet with total 2500 rows in a file.
Input:
10,11,12,A,3
10,11,12,A,4
10,11,12,B,3
OUTPUT:
10,11,12,B,3
text-processing awk uniq
text-processing awk uniq
edited Aug 31 at 13:49
ñÃÂsýù÷
16k92563
16k92563
asked Aug 31 at 12:43
ñÃÂñýàñüÃÂÃÂùcñ÷
417419
417419
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
With awk
:
awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile
Here, we are processing input infile
two times, first read the file and saving each duplicated lines according to the specified fields $2
, $3
and $4
into the associated array named dup
; the ++
is incrementing those lines occurrences every time.
At next process, checking and will print the entire line if the specified fields occurred only once.
add a comment |Â
up vote
0
down vote
For example:
egrep '^[^,]*,11,12,B,' input.file
Explain:
^
from begining of the line
[^,]
anything what is not the ','
*
as many times as possible
,11,12,B,
that what you search for
1
field 2 and 3 are not static numbers.
â msp9011
Aug 31 at 13:05
Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, theawk
is the right solution. (as ñÃÂsýù÷ wrote)
â schweik
Aug 31 at 13:22
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
With awk
:
awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile
Here, we are processing input infile
two times, first read the file and saving each duplicated lines according to the specified fields $2
, $3
and $4
into the associated array named dup
; the ++
is incrementing those lines occurrences every time.
At next process, checking and will print the entire line if the specified fields occurred only once.
add a comment |Â
up vote
3
down vote
With awk
:
awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile
Here, we are processing input infile
two times, first read the file and saving each duplicated lines according to the specified fields $2
, $3
and $4
into the associated array named dup
; the ++
is incrementing those lines occurrences every time.
At next process, checking and will print the entire line if the specified fields occurred only once.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
With awk
:
awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile
Here, we are processing input infile
two times, first read the file and saving each duplicated lines according to the specified fields $2
, $3
and $4
into the associated array named dup
; the ++
is incrementing those lines occurrences every time.
At next process, checking and will print the entire line if the specified fields occurred only once.
With awk
:
awk -F, 'NR==FNR dup[$2, $3, $4]++; next (dup[$2, $3, $4]==1)' infile infile
Here, we are processing input infile
two times, first read the file and saving each duplicated lines according to the specified fields $2
, $3
and $4
into the associated array named dup
; the ++
is incrementing those lines occurrences every time.
At next process, checking and will print the entire line if the specified fields occurred only once.
edited Aug 31 at 13:57
answered Aug 31 at 13:11
ñÃÂsýù÷
16k92563
16k92563
add a comment |Â
add a comment |Â
up vote
0
down vote
For example:
egrep '^[^,]*,11,12,B,' input.file
Explain:
^
from begining of the line
[^,]
anything what is not the ','
*
as many times as possible
,11,12,B,
that what you search for
1
field 2 and 3 are not static numbers.
â msp9011
Aug 31 at 13:05
Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, theawk
is the right solution. (as ñÃÂsýù÷ wrote)
â schweik
Aug 31 at 13:22
add a comment |Â
up vote
0
down vote
For example:
egrep '^[^,]*,11,12,B,' input.file
Explain:
^
from begining of the line
[^,]
anything what is not the ','
*
as many times as possible
,11,12,B,
that what you search for
1
field 2 and 3 are not static numbers.
â msp9011
Aug 31 at 13:05
Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, theawk
is the right solution. (as ñÃÂsýù÷ wrote)
â schweik
Aug 31 at 13:22
add a comment |Â
up vote
0
down vote
up vote
0
down vote
For example:
egrep '^[^,]*,11,12,B,' input.file
Explain:
^
from begining of the line
[^,]
anything what is not the ','
*
as many times as possible
,11,12,B,
that what you search for
For example:
egrep '^[^,]*,11,12,B,' input.file
Explain:
^
from begining of the line
[^,]
anything what is not the ','
*
as many times as possible
,11,12,B,
that what you search for
edited Aug 31 at 13:11
answered Aug 31 at 13:04
schweik
1804
1804
1
field 2 and 3 are not static numbers.
â msp9011
Aug 31 at 13:05
Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, theawk
is the right solution. (as ñÃÂsýù÷ wrote)
â schweik
Aug 31 at 13:22
add a comment |Â
1
field 2 and 3 are not static numbers.
â msp9011
Aug 31 at 13:05
Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, theawk
is the right solution. (as ñÃÂsýù÷ wrote)
â schweik
Aug 31 at 13:22
1
1
field 2 and 3 are not static numbers.
â msp9011
Aug 31 at 13:05
field 2 and 3 are not static numbers.
â msp9011
Aug 31 at 13:05
Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the
awk
is the right solution. (as ñÃÂsýù÷ wrote)â schweik
Aug 31 at 13:22
Well, all lines, where patern formed with (field 2, field 3, field 4) are repeated only once? If so, the
awk
is the right solution. (as ñÃÂsýù÷ wrote)â schweik
Aug 31 at 13:22
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%2f466029%2fprint-lines-with-unique-specified-fields%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