grep '.*|.*|.*'
will select lines with at least three fields and two separators.
bash - extracting lines that contain only 3 columns
-
30-05-2022 - |
Question
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 2
OTHER TIPS
since you said grep is allowed:
grep -E '^([^|]*\|){2}[^|]*$' file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow