Help with awk command to extract messages


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with awk command to extract messages
# 1  
Old 10-11-2010
Java Help with awk command to extract messages

Need expert's opinion urgently.

I have a file which contains messages.
A message is separated by $ in this file.
In each message we need to get string aftr :20: and send it to an output file. If :20: is not prsent in a message then we need to search for :20C: and send the corresponding string to o/p file. if dat too is not present then search :20D: in same message. If nothing prsent among :20:,:20C:,:20D: then we need to send a blank line to o/p corresponding to that message.
Please help.

like
{1:F01ADA00}{2:I 05 }{4:

-}${1:F01ADAGGB2SA}{2:O9500000000}{3:{108:094123}}{4:
:20:STMMYM0
-}
o/p file:
<BLANK LINE>
STMMYM0


Many Thanks in advance.

Last edited by Opamps123; 10-11-2010 at 08:04 AM..
# 2  
Old 10-11-2010
Try:
Code:
perl -l -0044ne '/:20(?:C|D)?:(.*)/;print $1' input > output

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 10-11-2010
Code:
awk -F ":20[:|C:|D:]" '{print $2}' infile

This User Gave Thanks to rdcwayx For This Post:
# 4  
Old 10-12-2010
MySQL

perl -l -0044ne '/:20(?:C|D)?Smilie.*)/;print $1' input > output

this worked fine for me.
Thanks bartus11. Smilie
Can you please explain the functionality.

awk command is throwing an error.
May be I am doing something wrong as I am not much aware abt the syntax.

awk: syntax error near line 1
awk: bailing out near line 1
# 5  
Old 10-12-2010
Quote:
Originally Posted by Opamps123
perl -l -0044ne '/:20(?:C|D)?Smilie.*)/;print $1' input > output

this worked fine for me.
Thanks bartus11. Smilie
Can you please explain the functionality.

awk command is throwing an error.
May be I am doing something wrong as I am not much aware abt the syntax.

awk: syntax error near line 1
awk: bailing out near line 1
In solaris, use nawk or /usr/xpg4/bin/awk
# 6  
Old 10-12-2010
Quote:
Originally Posted by bartus11
Try:
Code:
perl -l -0044ne '/:20(?:C|D)?:(.*)/;print $1' input > output

Seems to print result from last match when line is missing all of :20: and :20C: and :20D:
This update fixes it by matching to nothing before doing the :20(CD): match

Code:
perl -l -0044ne '/()/;/:20(C|D)?:(.*)/;print $2' input > output


Last edited by Chubler_XL; 10-12-2010 at 11:56 PM.. Reason: Formatting
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk/sed command to extract the string between 2 patterns but having some particular value

Hi - i have one file with content as below. ***** BEGIN 123 ***** BASH is awesome ***** END ***** ***** BEGIN 365 ***** KSH is awesome ***** END ***** ***** BEGIN 157 ***** KSH is awesome ***** END ***** ***** BEGIN 7123 ***** C is awesome ***** END ***** I am trying to find all... (4 Replies)
Discussion started by: reldb
4 Replies

2. Shell Programming and Scripting

extract column with awk

This is a example TXT file: ID CDR1 CDR2 CDR3 1 CDR1 CDR3 2 CDR1 CDR2 CDR3 3 CDR3 What I want to do is extract the fourth column with awk, however, there are some blank space in some field. I get wrong result when it print out awk result. awk '{print $1,$4}'... (8 Replies)
Discussion started by: xshang
8 Replies

3. Shell Programming and Scripting

extract the data using AWK command

In a file i have a data like INPUT: no,name,company 1,vivek,hcl 2,senthil,cts 1,narsi,hcl 4,prabhakaran,ibm OUTPUT: 1,vivek,hcl 1,narsi,hcl Using AWK command i want to display the names those having no:1 and company:hcl.Please tell me the command to display above result. (8 Replies)
Discussion started by: katakamvivek
8 Replies

4. Shell Programming and Scripting

need extract command

Hi, I am having an file 20110909.tar.gz (path-home/user01/archive/20110909.tar.gz ), contains some log files some csv files I want to extract that files . if i run "ls" command then their should be display all the log files and csv files on the same path. please help me to know the... (4 Replies)
Discussion started by: aish11
4 Replies

5. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

6. Shell Programming and Scripting

Help with extract using awk

I am trying to get the filenames which is $9 when i use ls -lrt but i am getting only some of the name using below command. ls -lrt *.edf is it bcs the filename has spaces in between them? How can I get the complete file name in cases like this? (19 Replies)
Discussion started by: dsravan
19 Replies

7. Shell Programming and Scripting

How to extract elements using Awk

Hi, I have this typical extraction problem in AWK. I have 3 input files.. i) First one is somehow like an oracle of:- foo 12,23,24 bla 11,34 car 35 ii)Second file is basically detailing the score for each of the second field of first file. Besides, for the first column, it is the... (3 Replies)
Discussion started by: ahjiefreak
3 Replies

8. Shell Programming and Scripting

Awk Command to extract Fields

Hi I am newbie.My requirement is: I have start time :Wed Apr 30 3:30:45 End time :Wed Apr 30 3:35:45 which is stored in a file. I have to extract timestamp 3:30:45 using awk. And Subtract the same The script: ---------- #!/bin/ksh LOG_FILE=$1 START_TIME=`head -2 $LOG_FILE... (1 Reply)
Discussion started by: usshell
1 Replies

9. Shell Programming and Scripting

AWK to extract information

Hi all, I am working on a shell script to extract information from a file that has output from Oracle sqlplus. The problem is that the output of a single line is spread across multiple lines and i do not know as how to extract the particular filed at ones,which spans multiple lines.... (2 Replies)
Discussion started by: harris2107
2 Replies

10. Programming

extract command

hey i want to extract an argument from double qoutes, eg: when the user enters: prompt "mile" i need to extract everything within the double quotes, in my case, mile, and save it to a string. feedback/code would be appreciated thanks mile1982 (1 Reply)
Discussion started by: mile1982
1 Replies
Login or Register to Ask a Question