0

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...

2
  • What do you mean by "just in different row"? Commented Dec 23, 2011 at 10:16
  • are you just asking to combine 3 files into 1? Commented Dec 23, 2011 at 10:19

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Don't even need the for loop, just sed 's/\s\+/,/g' file* > out.csv
Nice one! Didn't know that (didn't read the manpage enough). Edited!
you don't need the echo either: sed 's/\s\+/,/g;1i server,date,filename,number' file*
Meh, I don't know sed that much, as you probably have figured out ;) I prefer the echo way for clarity reasons but will remind that i command though.
one thing more can we add filter functionality also...is iot possible?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.