Grep & sed - Output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep & sed - Output
# 8  
Old 11-22-2012
post your command and data in CODE tag

https://www.unix.com/how-post-unix-li...code-tags.html

is your log file gsc_1_20121121.log contains only two lines ?

what is the next word of OrderId: for the KR000002600016-SO
# 9  
Old 11-22-2012
Done...its working fine with below command:

Code:
cat gsc_20121121.log | grep ProcessNewOrderSingleTxnDelegate | 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: \(.*\)/\1:\2,\3,\5/p"

Thanks for your time

Last edited by Scrutinizer; 11-22-2012 at 07:31 AM.. Reason: code tags
# 10  
Old 11-22-2012
Quote:
Originally Posted by irfanmemon
Done...its working fine with below command:

cat gsc_20121121.log | grep ProcessNewOrderSingleTxnDelegate | 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: \(.*\)/\1:\2,\3,\5/p"

Thanks for your time
grep itself can read the file. so you dont need to use cat


Code:
 
  grep ProcessNewOrderSingleTxnDelegate gsc_20121121.log | sed .....

you can use the below awk.
Code:
 
 
awk '/ProcessNewOrderSingleTxnDelegate/ {sub(",",":",$2);for(i=1;i<=NF;i++){if($i~/OrderId/){o=$(i+1);break;}}print $1" "$2","o","$NF;}' gsc_20121121.log

This User Gave Thanks to itkamaraj For This Post:
# 11  
Old 11-22-2012
Thanks working fine
# 12  
Old 11-22-2012
Hi
The log file(gsc_1_20121121.log) looks like below



Code:
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

You can try the following.


awk -F" " '{print $1,$2,$12,$16}' inputfile|tr "," ":"|tr " " ","|sed 's/2012-11-21,/2012-11-21 /g'

Last edited by Scrutinizer; 11-22-2012 at 07:31 AM.. Reason: code tags
# 13  
Old 11-22-2012
Code:
sed 's!\([^,]*\),\([^ ]*\).*KR\([^ ]*\).*KR\(.*\)!\1:\2,KR\3,KR\4!g'  infile

# 14  
Old 11-22-2012
In this particular case:
Code:
awk '{sub(/,/,":"); print $1 FS $2,$12,$16}' OFS=, infile

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