0

Example:

I have a file that has following data:

cvrta2100 Error 404 Fixed

cvrta2111 Licensed  Needs Fixing

cvrta2123 Error 404 Fixed

cvrta2333 Licensed  Needs Fixing

I am using awk to print this output to an Excel file:

awk 'BEGIN{ OFS="|"; print "Hosts|Output|Status"}; NR > 1{print $1, $2, $3, $4, $5, $6, $7, $8, $9;}' input.txt > Output.xls

The problem is - I am only able to get the results in a single cell i.e. "cvrta2333 Licensed Needs Fixing" is all printed in a single cell.

My question: Is it possible to print each word Hosts, Output and Status in a different cell i.e. cvrta2333 (One Cell) Licensed (Next Cell) Needs Fixing (Next Cell)

3

For "simple" columns like this, comma separated values will open nicely in excel.

awk 'BEGIN{ OFS=","; print "Hosts,Output,Status"}; NR > 1{print $1, $2, $3, $4, $5, $6, $7, $8, $9;}' input.txt > Output.csv
0

If you import the file in Excel natively, you can use the "text to table" function (or whatever it's called) to break lines into columns using a space delimiter.

I don't know how Excel will react, but you can convert your file into one with tab- or comma-delimited words using tr,

$ tr \   \\t  < input > output
$ tr \   ,    < input > output

I'd stay away from CSV unless that was the only one that made Excel happy, because of the need to quote commas that are part of the logfile text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.