How to get the first line of an input text file, while deleting that line from the text file

text processing

How can I get the first line of an input text file, while deleting that line from the text file?

If I had a text file /myPathToTheFile.txt like this

► put returns between paragraphs
► for linebreak add 2 spaces at end
► _italic_ or **bold**

I'd like to get this line as an output

► put returns between paragraphs

and my text file should be now like this

► for linebreak add 2 spaces at end
► _italic_ or **bold*

Best Answer

ex -s /myPathToTheFile.txt <<\EX
1p
1d
wq
EX

or

ex -s /myPathToTheFile.txt <<< 1p$'\n'1d$'\n'wq

or, less typing:

ed -s /myPathToTheFile.txt <<< $'1\nd\nwq'
Related Question