3

INPUT:

CC2352345|m,safnlasndfmnyxdcvyxcvyxcv             |klasjdf |3|lasdjflasdf|                    |2345567356
CC3543353|asdfasdffghntz                          |klasjdf |3|lsajdfl |                       |3456561235
CC5634554|asfjmklasdfassasdasasdsdfas             |klasjdf |3|lsajdfl |                       |2345635636
     |masdfjklasdfjasldfjlasjdfklas|          | |       |                       |2345234566
CC4723456|asdjkfasjkldfjaklsjdflkajldkfjlasjdflk  |klasjdf |2|lsajdfl |                       |2345234525
DD3455463|asldfklklfaem,.rtklqerktljekltjklqe     |klasjdf |3|lsajdfl |                       |4565467546

OUTPUT:

CC2352345|m,safnlasndfmnyxdcvyxcvyxcv             |klasjdf |3|lasdjflasdf|                    |2345567356
CC3543353|asdfasdffghntz                          |klasjdf |3|lsajdfl |                       |3456561235
CC5634554|asfjmklasdfassasdasasdsdfas             |klasjdf |3|lsajdfl |                       |2345635636
CC4723456|asdjkfasjkldfjaklsjdflkajldkfjlasjdflk  |klasjdf |2|lsajdfl |                       |2345234525
DD3455463|asldfklklfaem,.rtklqerktljekltjklqe     |klasjdf |3|lsajdfl |                       |4565467546

QUESTION: How can I delete lines that has an empty first column?

2 Answers 2

5

Use this:

sed '/^\s\s*/d' file

Or even:

grep -v '^\s' file
4
  • 1
    How about /^\s*|/d?
    – jw013
    Apr 2, 2012 at 19:58
  • You can do it any way you'd like. I can write another ten solutions for that like sed -n '/^\S/p'. But does it matter?
    – rush
    Apr 2, 2012 at 20:03
  • 1
    You should be asking the OP whether it matters, not me. I'm just here to point out that the /^\s\s*/d will let lines like |... slip through whereas /^\s*|/d will not.
    – jw013
    Apr 2, 2012 at 20:47
  • Hm.. Yeap you're right. So thank you for your comment and explanation (: At the first time I thought there is no difference in output between your and mine regexes. But there is. And now I see it.
    – rush
    Apr 2, 2012 at 21:02
1

How about awk, because it hasn't been mentioned?

awk -F\| '$1~/\w/' file
2
  • Note that \w is specific to gawk. You could write more portably: awk -F '[ \t]*\\|' '$1 != ""' file Apr 2, 2012 at 21:27
  • awk -F\| '$1!~/^ *$/'
    – Peter.O
    Apr 3, 2012 at 0:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .