How to replace the first line using sed?
24,013
You can use -i
flag to sed
which will edit in-place and also take backup:
sed -i.bak "1 s/.*/$new_header/" inputfile
Note that the -i
option is non-standard and may work differently in different implementations of sed
. See How can I achieve portability with sed -i (in-place editing)?
Related videos on Youtube
Author by
William R
Updated on September 18, 2022Comments
-
William R over 1 year
Hi i am trying to replace the header line from my file using the sed command as mentioned below,
sed "1s/.*/$new_header/" Test_file.csv
The above line replaces the header and prints in stdout , But How can i redirect the output to new file or replace in the files directly ?
sed "1s/.*/$new_header/" Test_file.csv > new_file.csv
The above command works fine , But i want to redirect to same file.
-
Kusalananda almost 3 years
-