0

This question already has an answer here:

Without using SED, is there shell script to copy the content from an input file to a output file, adding a blank line between every two lines of the input file (double spacing)? I

marked as duplicate by don_crissti, Tomasz, sam, HalosGhost, Thomas Dickey Dec 3 '16 at 21:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 7
    "without using sed" smells like homework... – don_crissti Dec 3 '16 at 19:15
  • is there shell script... easy answer : yes. – steve Dec 3 '16 at 19:36
0
IFS=""
while read -r LINE
do
  echo "$LINE"
  echo
done

If it bothers you that it adds a blank line after the last line, one can do:

IFS=""
FIRST=y
while read -r LINE
do
  if [ "$FIRST" != "y" ]
  then
    echo
  fi
  FIRST=n
  echo "$LINE"
done
0

This appears to achieve what you're after.

If NR (line number) is divisible by 2, tag an extra newline at the end. And then print the line.

$ awk 'NR%2==0{$0=$0"\n"}1' foo.txt
line1
line2

line3
line4

line5
$

If it's merely a blank line between every line, use this

$ awk '{print $0,"\n"}' foo.txt
line1

line2

line3

line4

line5

$
  • "between every two lines" not every two lines. -1. – Tomasz Dec 3 '16 at 19:23
  • If?! Come on... – Tomasz Dec 3 '16 at 19:37

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