Add text to specified line

Hi All,

I am writing a script in which i need to add text "ABC" at line 14 in file input.txt

Can someone please help me how to do it? Thanks.

Regards,
Tushar

What have you tried and what kind of errors did you get?

I don't have much idea how file editing can be done within a shell script. I googled for it and came to know some commands like awk and ed can be useful but not sure what would be the exact command for doing this. Thanks.

Hello,

Try this.

 
awk '{s=$0; if( NR==14 ){ s=s " ABC" } print s;}' inputfile > outfile

Modify accordingly..

Thanks
Krsnadasa

Hi tushar_shah06,

One way using perl (change number 3 with your line number):

$ cat infile
one
two
three
four
five
six
seven
eigth
nine
$ perl -lpe 'substr $_, length , 0, q/ ABC/ if $. == 3' infile
one
two
three ABC
four
five
six
seven
eigth
nine
awk 'NR==14{$0 = $0 "TEXT"}1' file

Hi,

Why not this?

sed with option i: - 
 
sed "Lineno i Notes : Paste Here " file.txt