Reputation: 75
I am trying to write data from three txt files in csv file.
three files contain below data
data in the file is in this format -server date filename number
first txt file as-
app1 11.12.16 name1 2
app1 11.12.17 name2 3
second as
app2 11.12.16 name1 2
app2 11.12.17 name2 3
and same for thrird file with server as app3
i want to put this data from these three files to one csv file using shell script. the data in the txt file is separated with space.
data should go in same manner just in different row.
One more thing can be put a heading in the first row as server date filename number and put filter? is it possible?
Thanks in advance...
Upvotes: 0
Views: 12068
Reputation: 121710
This is a way to do it:
(
echo "server,date,filename,number"; sed 's/\s\+/,/g' file*
) >target.csv
This doesn't reorder rows, though.
Upvotes: 3