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
  • Welcome to the network. Please read the formatting guidelines: unix.stackexchange.com/editing-help and format your questions in a better form in future. Commented Jun 5, 2015 at 21:55

4 Answers 4

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.

2
  • 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 Commented Jun 6, 2015 at 0:55
  • I see that you are new to Unix SE. If you are satisfied with an answer, please consider accepting it. Commented Jun 6, 2015 at 0:57
1

With sed:

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

or:

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

With awk:

awk '/^$/{p++};p' file 
1

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

cat <example.txt <#"" 
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.

4
  • 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? Commented Jun 6, 2015 at 11:54
  • @roaima - who is they? Commented Jun 6, 2015 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. Commented Jun 6, 2015 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. Commented Jun 6, 2015 at 21:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.