I am writing a script that iterates through all the files and replaces line feeds at the beginning of each file. For a file like this,
\n
\n
A line \r\n
Another line \r\n
\r
\f
\n
\n
Few more lines \r\n
\r\n
I need to replace all line feeds at the beginning of the file with CRLF, i.e.
\r\n
\r\n
A line \r\n
Another line \r\n
\r
\f
\n
\n
Few more lines \r\n
\r\n
I tried using,
sed -i 's/^[\n]/\r\n/' file.txt
But it doesn't seem to work.
Edit: I am able to replace a range of lines with,
sed '1,2s/^/\r/'
But is there a way to identify if the first character in the file is line feed?
sed
to a range of lines, simply specify them (e.g. lines 1 to 5):sed '1,5command' file
– FelixJN Aug 12 '15 at 09:13