• Home
  • Uncategorized
  • Insert a character at the beginning of a nth line of a file in sed

Insert a character at the beginning of a nth line of a file in sed

sed '2s/.*/#&/' input.txt >output.txt

for 2nd line

One can also use inplace substitution

sed -i '2s/.*/#&/' input.txt