Reputation: 361
Is there a way to add a string in a specific line in a file and if something else is there replace it?
eg
command "HELLO" nth_line file
Upvotes: 1
Views: 1397
Reputation: 29437
Substitute "HELLO" in filename
at line 2
awk 'NR==2{gsub(/.*/, "HELLO")}1' filename
Upvotes: 1
Reputation: 182794
Sure:
sed '42s/.*/something else/'
However this won't work if the file fewer than 42 lines.
Upvotes: 1