Reputation: 173
I have a CSV file and I want to insert a header line to the CSV file.
The header will be:
SYSNAME,OBJSTRUC,AddChange,EN
When I use:
echo hello new line > filename.csv
it adds the new line but deletes everything from the CSV file.
Upvotes: 0
Views: 4429
Reputation: 5152
I would use the Sed
command
sed -i '1s/^/SYSNAME,OBJSTRUC,AddChange,EN\n/' filename.csv
Upvotes: 0
Reputation: 5874
@echo off
echo SYSNAME,OBJSTRUC,AddChange,EN > csv.tmp
type your.csv >> csv.tmp
del your.csv
ren csv.tmp your.csv
Using the redirection parameters you can first echo
the header in a temporary file and then type
the contents of your csv-file right after.
Then del
ete the original .csv and ren
ame the temporary one to the original one.
Note the difference between >
(overwrite the file with redirected text) and >>
(append to the bottom of redirection context).
Upvotes: 1