0

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

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Nadav Peled
  • 951
  • 1
  • 13
  • 19

2 Answers2

1

since you said grep is allowed:

grep -E '^([^|]*\|){2}[^|]*$' file
Kent
  • 189,393
  • 32
  • 233
  • 301
0

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

Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96