Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Use this:

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

Or even:

grep -v '^\s' file
share|improve this answer
1  
How about /^\s*|/d? –  jw013 Apr 2 '12 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 '12 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 '12 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 '12 at 21:02

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.