0

I want to replace the first two lines with a blank line as below.

Input:

sample
sample
123
234
235
456

Output:

<> blank line
123
234
235
456
Adrian
  • 468
  • 2
  • 6
  • 15
  • got the answer here [skipping lines in bash](https://stackoverflow.com/questions/604864/print-a-file-skipping-the-first-x-lines-in-bash) tl;dr: sed 1,2d file.txt – Toshio Jun 15 '22 at 11:45
  • this is rmoving first two lines but blank line should be there in output file... – Jashwanth CH Jun 15 '22 at 11:51

1 Answers1

1

Delete the first line, remove all the content from the second line but don't delete it completely:

$ sed -e '1d' -e '2s/.*//' input.txt

123
234
235
456

Or insert a blank line before the first, and delete the first two lines:

$ sed -e '1i\
' -e '1,2d' input.txt

123
234
235
456

Or use tail instead of sed to print all lines starting with the third, and an echo first to get a blank line:

(echo ""; tail +3 input.txt)

Or if you're trying to modify a file in place, use ed instead:

ed -s input.txt <<EOF
1,2c

.
w
EOF

(The c command changes the given range of lines to new content)

Shawn
  • 47,241
  • 3
  • 26
  • 60