BASH: Reformatting text output to join lines
Hello all,
I am working on a script to collect I/O metrics and am having trouble reformatting output from the iostat command. Specifically, some "normally single line" rows of data are being placed as double line results (OUTPUT 1). I expect this has to do with output formatting rules within the utility itself, but have been unable to "unify" the two lines back into one. What are some recommended solutions to obtain a desirable result (EG: RESULT 1)? I would like to use tools suitable to include in a command pipeline if possible (EG: sed, tr, awk, etc). The spacing is less important as I plan to cut the results up with awk and convert to CSV. # OUTPUT 1 Code:
[20:42:45:user@hostname:~] Code:
[20:42:45:user@hostname:~] Thanks for your time. |
Does this happen only when you output to screen, or also when you redirect to a file?
|
Quote:
Thanks for the above reply. Indeed this is a problem which occurs in both scenarios (screen && file). I am writing to a file with a simple STDOUT redirection ( Code:
command > file.txt |
Quote:
Quote:
Code:
awk '{ if (NF>1) printf("%s\n", $0); else printf("%s\t", $0); }' Quote:
Code:
awk '(NF==1) { getline temp; $0 = $0 "\t" temp; } Code:
#!/bin/bash Code:
env LANG=C LC_ALL=C iostat -d -x |
Quote:
Thanks for the in-depth response. This fixed my issue beautifully! :-D |
All times are GMT -5. The time now is 02:29 AM. |