split a line using a token


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting split a line using a token
# 1  
Old 12-03-2008
split a line using a token

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.
# 2  
Old 12-03-2008
Tsk, just answered my own question, this is what needs to be done :

grep "whatever" filename | while read LINE; do echo $LINE; done;
# 3  
Old 12-04-2008
i don't think it will work.. its not working for me
# 4  
Old 12-04-2008
this simple sed code worked for me...
Code:
sed 's/millis] /&\
/g' input_file

# 5  
Old 12-04-2008
Use double quotes.
Code:
# 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]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Sh: -c: line 0: syntax error near unexpected token `(' how to resolve this

Below query is not working for me. Please help me on this DATA EXCLUDE STATEMENT: TABLE:\"LIKE \'%\_HISTORY\'\", TABLE:\"LIKE \'%\_HIST\'\", TABLE:\"in \(select tname from tab where REGEXP_LIKE(TNAME,\'\_H$\'\))\", TABLE:\"LIKE \'%\_LOG\'\", TABLE:\"LIKE \'DW\_%\'\", TABLE:\"LIKE... (1 Reply)
Discussion started by: princy
1 Replies

2. Shell Programming and Scripting

Split a line

I have a very long line in a file separated by "|" delimiter like below. Due to the length of the line, I find it very difficult to read to find a match line. file = temp.txt word 1| word 2 | word 3|.... I would like to read the file temp.txt and print out all words line by line like... (1 Reply)
Discussion started by: boldnbeautiful
1 Replies

3. Shell Programming and Scripting

Read a File line by line and split into array word by word

Hi All, Hope you guys had a wonderful weekend I have a scenario where in which I have to read a file line by line and check for few words before redirecting to a file I have searched the forum but,either those answers dint work (perhaps because of my wrong under standing of how IFS... (6 Replies)
Discussion started by: Kingcobra
6 Replies

4. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

5. Shell Programming and Scripting

sed - Removing all characters from token to end of line

Hello. The token is any printable characters between 2 " . The token is unknown, but we know that it is between 2 " Tok 1 : "1234x567" Tok 2 : "A3b6+None" Tok 3 : "A3b6!1234=@" The ligne is : Line 1 : "9876xABCDE"Do you have any code fragments or data samples in your post Line 2 : ... (3 Replies)
Discussion started by: jcdole
3 Replies

6. Shell Programming and Scripting

Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'

first of all I thought the argument DONE is necessary for all scripts that have or begin with do statements which I have on my script, However, I still don't completely understand why I am receiving an error I tried adding another done argument statement but didn't do any good. I appreciate... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

7. Shell Programming and Scripting

Split a line

I guess this has a simple solution but can't figure out now. having: x="H:a:b:c" to get H: echo $x|awk -F: {'print $1'} how can I put REST of line in another one? i.e. echo $rest a:b:c thanks ---------- Post updated at 08:58 PM ---------- Previous update was at... (5 Replies)
Discussion started by: garagonp
5 Replies

8. Shell Programming and Scripting

split single line into two line or three lines

Dear All, I want to split single line into two line or three lines wherever “|” separated values comes using Input line test,DEMTEMPUT20100404010012,,,,,,,,|0070086|0070087, output shoule be test,DEMTEMPUT20100404010012,,,,,,,,0070086, test,DEMTEMPUT20100404010012,,,,,,,,0070087, (14 Replies)
Discussion started by: arvindng
14 Replies

9. Shell Programming and Scripting

Split a line on positions before reading complete line

Hi, I want to split before reading the complete line as the line is very big and its throwing out of memory. can you suggest. when i say #cat $inputFile | while read eachLine and use the eachLine to split its throwing out of memory as the line size is more than 10000000 characters. Can you... (1 Reply)
Discussion started by: vijaykrc
1 Replies

10. UNIX Desktop Questions & Answers

line 3: syntax error near unexpected token `('

Hi All I've used UNIX in the past experimenting with commands through terminal but thats about it. Im now currently teaching myself "C". Using a book from the library, the first chapter asks you run and compile your program from a command-line prompt. As you will see the program is very simple,... (4 Replies)
Discussion started by: camzio
4 Replies
Login or Register to Ask a Question