Grep & sed - Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep & sed - Output
# 1  
Old 11-22-2012
Grep & sed - Output

Hi All,

Facing an issue with grep & sed

I have logs as below:

Code:
gsc_1_20121121.log:2012-11-21 10:09:13,143  INFO [com.clsa.fms.orders.workers.destinationresponseworker.NewOrderSingleTask] - fmsspace.1 [1] [CommandDispatcherThread-0] ProcessNewOrderSingleRequest: Result - ProcessNewOrderSingleBatchResultDTO - success:true,newOrderSingleBatchResults:ProcessNewOrderSingleResultDTO - resultantOrders:OrderId: KR000002601583-SO OrderRoutingId: 0 RequestId: KR000002601583-O,success:true,,

I got output as :
Code:
2012-11-21 10:09:13,143,KR000002601583-SO,KR000002601583-O

when I used below command:
Code:
grep ProcessNewOrderSingleBatchResultDTO | sed -n -e "s/.*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\),\([0-9][0-9][0-9]\).*OrderId: \(.*\).* OrderRoutingId: \(.*\).* RequestId: \(.*\),success:true.*/\1:\2,\3,\5/p" gsc_1_20121121.log

Can any one help me how I can get output
Code:
2012-11-21 10:09:13,141,KR000002601583-SO,KR000002601583-O

from below log

Code:
gsc_1_20121121.log:2012-11-21 10:09:13,141  INFO  [com.clsa.fms.orders.bs.impl.delegates.local.impl.ProcessNewOrderSingleTxnDelegate]  - fmsspace.1 [1] [LRMI Connection-pool-1-thread-12] resultantOrders:  OrderId: KR000002601583-SO OrderRoutingId: 0 RequestId: KR000002601583-O


Last edited by Scrutinizer; 11-22-2012 at 04:48 AM.. Reason: code tags
# 2  
Old 11-22-2012
Code:
 
$ nawk '{for(i=1;i<=NF;i++){if($i~/OrderId/){o=$(i+1);break;}}print $1 $2","o","$NF;}' gsc_1_20121121.log
2012-11-2110:09:13,141,KR000002601583-SO,KR000002601583-O

# 3  
Old 11-22-2012
Thanks but can you help me with the similar way I have done for 1st one..Thanks
# 4  
Old 11-22-2012
Code:
 
when I used below command:
grep ProcessNewOrderSingleBatchResultDTO | sed -n -e "s/.*\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]\),\([0-9][0-9][0-9]\).*OrderId: \(.*\).* OrderRoutingId: \(.*\).* RequestId: \(.*\),success:true.*/\1:\2,\3,\5/p" gsc_1_20121121.log

in you command, you didnt provide the filename to grep command.

Code:
 
grep "PATTERN" filename | your sed command

---------- Post updated at 01:49 PM ---------- Previous update was at 01:48 PM ----------

Post the detailed log and let us know the required output.
# 5  
Old 11-22-2012
The log file(gsc_1_20121121.log) looks like below

Code:
2012-11-21 08:41:07,367  INFO [com.clsa.fms.orders.bs.impl.delegates.local.impl.ProcessNewOrderSingleTxnDelegate] - fmsspace.1 [1] [LRMI Connection-pool-1-thread-9] resultantOrders: OrderId: KR000002600016-SO OrderRoutingId: 0 RequestId: KR000002600016-O
2012-11-21 08:44:33,499  INFO [com.clsa.fms.orders.bs.impl.delegates.local.impl.ProcessNewOrderSingleTxnDelegate] - fmsspace.1 [1] [LRMI Connection-pool-1-thread-9] resultantOrders: OrderId: KR000002600017-SO OrderRoutingId: 0 RequestId: KR000002600017-O

Desired output
Code:
2012-11-21 08:41:07:367,KR000002600016-SO,KR000002600016-O
2012-11-21 08:44:33:499,KR000002600017-SO,KR000002600017-O


Last edited by Scrutinizer; 11-22-2012 at 04:49 AM.. Reason: code tags
# 6  
Old 11-22-2012
Code:
$ nawk '{sub(",",":",$2);for(i=1;i<=NF;i++){if($i~/OrderId/){o=$(i+1);break;}}print $1" "$2","o","$NF;}' gsc_1_20121121.log
2012-11-21 08:41:07:367,KR000002600016-SO,KR000002600016-O
2012-11-21 08:44:33:499,KR000002600017-SO,KR000002600017-O

if you dont have nawk, try with awk
This User Gave Thanks to itkamaraj For This Post:
# 7  
Old 11-22-2012
When I am running
Code:
awk '{sub(",",":",$2);for(i=1;i<=NF;i++){if($i~/OrderId/){o=$(i+1);break;}}print $1" "$2","o","$NF;}' gsc_1_20121121.log

Its giving me output as below:
Code:
2012-11-21 08:41:07:367,,KR000002600016-SO 2012-11-21 08:44:33:499,,KR000002600017-SO


Last edited by Scrutinizer; 11-22-2012 at 07:30 AM.. Reason: code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Trim sed output & assign to variable

Hi, I have the following command that parses an xml file to read a node <port>'s value. Hoever the output comes with spaces. My requirement is to trim the spaces around the value and assign to a variable. sed -n 's|<port>\(.*\)</port>|\1|p' ../cfg.xml How do I go about it? (6 Replies)
Discussion started by: sai2013
6 Replies

2. Shell Programming and Scripting

help understanding regex with grep & sed

I have the following line of code that works wonders. I just don't completely understand it as I am just starting to learn regex. Can you help me understand exactly what is happening here? find . -type f | grep -v '^\.$' | sed 's!\.\/!!' (4 Replies)
Discussion started by: trogdortheburni
4 Replies

3. Shell Programming and Scripting

grep with date & unique output

alert.log has the entries with ORA-XXXX, .... Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:08:09 2012 WARNING: inbound connection timed out (ORA-3136) Mon Sep 24 15:15:01... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

4. Shell Programming and Scripting

sed & remove duplicates on output

sed -e '1d' -e 's/^\(]\{2\}\)-\(]\{3\}\)-\(]\{4\}\).*/"0000020\1\200\3"\,/g' abc.txt This script returns many duplicates due to the duplciates in the .txt file. i.e. ... "000002012149000060", "000002012149000064", "000002012149000064", "000002012149000064", "000002012149000064",... (9 Replies)
Discussion started by: Daniel Gate
9 Replies

5. Shell Programming and Scripting

applescript & grep - sed command

I'm new using Unix commands in applescript. The following script you choose different folders with PDfs, get file count of PDfs on chosen folders, & write the results in text file. set target_folder to choose folder with prompt "Choose target folders containing only PDFs to count files" with... (0 Replies)
Discussion started by: nellbern
0 Replies

6. Shell Programming and Scripting

Awk & sed query for output

Hello, I have a file. its content are like below. mdn:87439842 imsi:23082038203 Ctime:12082010 01:20:10 mdn:9324783783 imsi:402349823322 Ctime: 12072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime: 23072010 01:20:10 mdn:87439842 imsi:23082038203 Ctime:18072010 01:20:10 mdn:87439842... (3 Replies)
Discussion started by: Sanket11
3 Replies

7. Shell Programming and Scripting

Help Needed with grep & sed

On one of my servers, it appears that a bunch of html files got the following code added to it... I was going to try to remove this line using grep & sed... as sample grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g' I can get the grep portion to work... grep "<script... (7 Replies)
Discussion started by: djlane
7 Replies

8. UNIX for Dummies Questions & Answers

Grep char count & pipe to sed command

Hi I am having a 'grep' headache Here is the contents of my file: (PBZ,CP,(((ME,PBZ,BtM),ON),((ME,((PBZ,DG),(CW9,PG11))),CW9,TS2,RT1))) I would like to count out how many times 'PBZ' occurs and then place that number in the line above 3... (8 Replies)
Discussion started by: cavanac2
8 Replies

9. Shell Programming and Scripting

grep & sed question

I'm trying to write a bash script to perform a tedious task, but I have no experience and hardly any knowledge so I've been having a rough time with it. I'm on Mac OS X, and I want a script to do the following: I have a directory that has about 200 sudirectories. In each of these directories,... (1 Reply)
Discussion started by: der Kopf
1 Replies
Login or Register to Ask a Question