RachSingla
RachSingla

Reputation: 63

Shell script output file to be saved in MSExcel

I have a Shell script output file

aa bb
cc dd
eee fff

and want to save this in excel sheet with two columns.

first  second
  aa      bb
  cc      dd
 eee      fff

Online browsing I found this

awk 'BEGIN{ OFS=" "; print "first|second"};
NR > 1{print "$0", "$1"}' input.txt > Output.xls

But I do not get the output file.

Upvotes: 0

Views: 3989

Answers (1)

glenn jackman
glenn jackman

Reputation: 247202

set your output field separator to be a comma, and you should be OK:

awk '
    BEGIN {OFS=","; print "first", "second"}
    {print $1, $2}
' input.txt > Output.xls

With awk, $0 is the complete record and $1 is the first field.
Also, you don't need to skip the first line of input.

Upvotes: 1

Related Questions