cesarNZ
December 3, 2008, 10:37pm
1
hi all,
is ksh, is there a way to split a line so it displays the output on seperate lines from a grep command ??
i have a script which greps for "responseTime" from log files but when i echo the output of the grep command it displays all occurances of the string all on one line which is hard to read.
i.e it currently displays this :
[12/4/08 16:18:31:298 NZDT] 4c4a8d responseTime [307 millis] [12/4/08 16:19:47:005 NZDT] 1affb08 responseTime[692 millis] [12/4/08 16:19:47:416 NZDT] 1affb08 responseTime[692 millis]
and i wanted to display it in this way :
[12/4/08 16:18:31:298 NZDT] 4c4a8d responseTime [307 millis]
[12/4/08 16:19:47:005 NZDT] 1affb08 responseTime[692 millis]
[12/4/08 16:19:47:416 NZDT]1affb08 responseTime[692 millis]
thanks in advance.
cesarNZ
December 3, 2008, 10:42pm
2
Tsk, just answered my own question, this is what needs to be done :
grep "whatever" filename | while read LINE; do echo $LINE; done;
i don't think it will work.. its not working for me
this simple sed code worked for me...
sed 's/millis] /&\
/g' input_file
danmero
December 3, 2008, 11:31pm
5
Use double quotes.
# var=$(grep response file)
# echo $var
[12/4/08 16:18:31:298 NZDT] 4c4a8d responseTime [307 millis] [12/4/08 16:19:47:005 NZDT] 1affb08 responseTime[692 millis] [12/4/08 16:19:47:416 NZDT]1affb08 responseTime[692 millis]
# echo "$var"
[12/4/08 16:18:31:298 NZDT] 4c4a8d responseTime [307 millis]
[12/4/08 16:19:47:005 NZDT] 1affb08 responseTime[692 millis]
[12/4/08 16:19:47:416 NZDT]1affb08 responseTime[692 millis]