user1113186
user1113186

Reputation: 75

How to generate a CSV from text files using shell scripting

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

Answers (1)

fge
fge

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

Related Questions