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

Était-ce utile?

La solution 2

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

Autres conseils

since you said grep is allowed:

grep -E '^([^|]*\|){2}[^|]*$' file
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top