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

Was it helpful?

Solution 2

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

OTHER TIPS

since you said grep is allowed:

grep -E '^([^|]*\|){2}[^|]*$' file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top