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

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'

At least with GNU sed:

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

$ sed -i '1{
w /dev/stdout
d}' file
► put returns between paragraphs

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

With GNU sed it can be written as a one-liner

sed -i -e '1 {w /dev/stdout' -e 'd}' file

Assuming you are asking for a shell script, this will do what you requested:

NAME=$1
head -n 1 $NAME
sed -i '1d' $NAME