Add one text line in the head of the file

hello,
how can I add one text line string at the line number one of a file.

thankx,

Try this,

sed -ri '1/s/(.*)/string\1/' file_name

the command not :work as

-bash-3.00$ sed -ri '1/s/(.*)/"my text"\1/' myfile
sed: illegal option -- r

Hi friend,I found the problem in your command.

You remove the slash character after 1.

You try this,

sed -ri '1s/(.*)/text\1/' inputfile

Even if you have problem with r option,you try the following.

sed -i '1s/\(.*\)/text\1/' inputfile

Hi Ahmed waheed sorry , I wrongly typed the command.

Try this,


sed -ri '1s/(.*)/string\1/' file_name

See the following example:

it will add the string into the first line of the text file

sed  -i  '1{s/^/string\n/}' fine_name