Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a file riddled with this kind of thing:

>> The big brown fox
>> jumps over the
>> lazy dog.
The end.

I want to get rid of "\n>>" and just turn this into a oneliner:

The big brown fox jumps over the lazy dog.
The end.

I'm trying the following, all of which refuse to work:

perl -pe 's/\r?\n>>//g' task.tex
tr '\n\>\>' '' < task.tex 
sed -i ':a;N;$!ba;s/\n>>//g' task.tex 

What am I doing wrong?

share|improve this question

Why do you have to run through so much of trouble? Here's what I just did with your piece of text.

  1. Open the file in GEdit.

  2. Keep the cursor on the start of the second line

  3. Use CTRL + H (Find and replace)

  4. Find for >> and replace with SPACE

  5. Find for \n and replace with SPACE

Make sure you use REPLACE ALL in both cases (4 and 5).

That's what I did and it worked :)

share|improve this answer
This would work just fine. Not sure why you would need to over complicate such a task. – Matthew Williams Feb 21 '14 at 9:12

Assuming the text is in a file called x.txt:

tr -d '\n>>' < x.txt | sed -e 's/-POEM-/&\n/' -e 's/\./&\n/g'
share|improve this answer

This worked for me:

while read line; do
         line1=`echo $line`;
         if [ `echo $line1 | grep "^>" | wc -l` -eq 1 ];
                 var1=`echo $line1 | sed 's/^...//'`;
                 line2=`echo $line2 $var1`;
                 echo $line2;
                 echo $line1;
done < task.tex
share|improve this answer
It is not necessary to fork a new subshell process just to assign the contents of a shell variable to another shell variable. – JdeBP Feb 21 '14 at 9:13
Thanks for aligning the code.. please also let me know a generic code for doing the above mentioned task!!! As the answer by Ketan is input specific. – Vipul Feb 21 '14 at 11:11

You must log in to answer this question.

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