Search code examples
bashsortingpipelinepipelining

bash - extracting lines that contain only 3 columns


I have a file that include the following lines :

2 | blah | blah
1 | blah | blah
3 | blah
2 | blah | blah
1
1 | high | five
3 | five

I wanna extract only the lines that has 3 columns (3 fields, 2 seperators...)
I wanna pipe it to the following commands :

| sort -nbsk1 | cut -d "|" -f1 | uniq -d

So after all I will get only :

2
1

Any suggestions ? It's a part of homework assignment, we are not allowed to use awk\sed and some more commands.. (grep\tr and whats written above can be used)

Thanks


Solution

  • grep '.*|.*|.*' will select lines with at least three fields and two separators.