Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 need a bash script that will take a file and add a second \n character for every \n character already in the file:

that is:




how do I start. OR, should I write it in another language and wrap it in bash?

share|improve this question
up vote 8 down vote accepted
sed 'G' file > newfile


perl -nae 'print "$_\n";' file > newfile


while read ln
   echo $ln; echo;
done < file > newfile
share|improve this answer

A very very simple way to do it.

cat inputfile.txt | while read a
echo $a >> outputfile.txt
echo "" >> outputfile.txt
share|improve this answer
wouldn't that be echo '\n' >>outputfile.txt or does echo automatically put in a newline? – mechko Feb 1 '10 at 17:14
@mechko - Yes, echo automatically puts in a newline – Nifle Feb 1 '10 at 17:18
use echo -n if you don't want echo to automatically output a newline. – quack quixote Feb 1 '10 at 19:06

sed can do this quite easily

sed 'G' file
share|improve this answer

Your Answer


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.