2

I'm trying to remove the content from the beginning of the text to the first blank line.

--($:~)-- cat example.txt   
pedro
pablo
juan

francisco 
emiliano
martin

So, I would delete:

pedro
pablo
juan

I tried with:

sed -n '/^/,/^$/ d' example.txt  

but it doesn't work.

1

You can do

 sed -n '/^$/{:l; p; n; b l}' file

The -n suppresses normal output. When you reach the first blank line, which is matched with the pattern /^$/, it starts a loop that prints all subsequent lines.

| improve this answer | |
  • Thats work perfect !! i added sed -i -n '/^$/{:l; p; n; b l}' example.txt;sed -i '1d' example.txt cat example.txt francisco emiliano martin – Teb Jun 6 '15 at 0:55
  • I see that you are new to Unix SE. If you are satisfied with an answer, please consider accepting it. – bkmoney Jun 6 '15 at 0:57
1

With sed:

sed -n '/^$/,$p' file

or:

sed -e '/^$/,$!d' file

With awk:

awk '/^$/{p++};p' file
| improve this answer | |
1

With a recent ksh (you need ksh93s or above), you could do:

cat <example.txt <#""
| improve this answer | |
1
sed -e 1,/^$/c\\ -e '' <infile >outfile

...would also work.

As opposed to 1,/^$/d the c\<EOF> command doesn't delete the address range, exactly, but rather changes the whole block to a single string. And so this will not remove the first blank line from output - because it changes the whole first occurring text block in input (as delimited by the first occurring blank line) to a single blank line.

| improve this answer | |
  • Your posts shouldn't be cropping up in the "low quality posts" queue! Can you expand this a little to explain to Teb why yours would work but theirs doesn't, or something? – roaima Jun 6 '15 at 11:54
  • @roaima - who is they? – mikeserv Jun 6 '15 at 12:09
  • They is a gender neutral he/she pronoun referencing Teb, the person who asked the original question. Perhaps our versions of English don't coincide so I'm sorry it wasn't clear. – roaima Jun 6 '15 at 21:15
  • @roaima - no, I don't think so. Looking at your comment now it is unmistakably clear to whom it was you referred. Somehow my initial reading of managed to miss entirely the two words to Teb. Weird. – mikeserv Jun 6 '15 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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