grep options in solaris


 
Thread Tools Search this Thread
Operating Systems Solaris grep options in solaris
# 1  
Old 08-30-2012
grep options in solaris

Hi,

I am interested in knowing the grep optiojs availabel in solaris box, to get the grep results in one line from the log files. only the matched values need to be displayed.

I need ot find the values in a message where the search values will be in separate lines of the input.
like:
Code:
[Aug 12 2012: 10:15;10]<student>
<name>Raj</name>
<age>29</age>
<id>1234</id>
<phone>12345467890</phone>
</student>

Moderator's Comments:
Mod Comment code tags please

and my search require to display [Aug 12 2012: 10:15;10] <id>1234</id> <phone>12345467890</phone> in one line. is it possible?

I am using solaris box.

How it is doen in solaris and in unix/linux.


Thanks.

Last edited by jim mcnamara; 08-30-2012 at 11:01 AM..
# 2  
Old 08-30-2012
PERL

Hi,

Welcome to unix and linux forum!!!

Please use code tags for code and data samples.

Check this out,

Code:
awk 'BEGIN{FS="<";ORS="";}/\[/{print "\n"$1;next;}/id|phone/{print;}END{print "\n";}' file

perl -ne 'chomp($_);if($_ =~ /\[/){$_ =~ s/<.*student>//g;print "\n",$_;}if($_ =~ /id|phone/){print $_;}END{print "\n";}' file

In grep you wont do much. certainly we can get matching string and do some matching stuff.
Cheers,
Ranga Smilie
This User Gave Thanks to rangarasan For This Post:
# 3  
Old 08-30-2012
Hi,

Thanks. Bu it diapays again complete message it doesn't listing time.

like:
Code:
29 Aug 2012 13:27:50 MsgID="12644861261" RID="RID0009229952" like this from all the logs present, per second wise search, like 29 Aug 2012 13:27:50, 29 Aug 2012 13:27:51, 29 Aug 2012 13:27:52 etc.

Sample:

Code:
<B>[29 Aug 2012 13:27:50] </B>Logger - Message Receipt~ABC 2012-08-29T13:27:50.220+01:00<soap-env:Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MyXML xmlns="http://www.protocol.org/XML-5-0" v="5.0">
<Main abc="2011-06-02T13:24:10" BizDt="2011-06-02" DT="2011-06-02" CVal="GBP" pp="105.07" LastQty="16" <B>MsgID="12644861261"</B> TStat="0" TrdTyp="0" RTyp="0" MTyp="0" 
--
--
--
<B>RID="RID0009229952"></B>
---
---
---
---
---
---</Main>
</MyXML>
</soap-env:Body>

where denoted by <B> </B> those I need to search for. only these three in one line. because I have lakhs of messages.


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.

Last edited by radoulov; 08-30-2012 at 11:26 AM..
# 4  
Old 08-30-2012
Hi,

Please use code tags for data samples and provide me full sample data and expected output.

Cheers,
Ranga Smilie
# 5  
Old 08-30-2012
I am sorry I don't know how to use the code tags.

mine is in an xml file.

in this xml file I need to search for two attribute elements with its values and the time when it is received in the log.

as showed in my earlier example.

Thanks a lot for your quick help.
# 6  
Old 08-30-2012
Please click the link 'code tags' on moderator comments to know, how to use code tags. Code tags will improve more readability.

Please provide your full data sample and expected output.

Cheers,
Ranga Smilie
# 7  
Old 08-30-2012
There is no link Rangarasan. it is disabled.

Ok. I am providing a sample message.

Code:
[INFO ] [29 Aug 2012 13:23:12] Logger  - Message Receipt~ABC 2012-08-29T13:23:12.135+01:00~MyAPP~Project/ProxyServices/Listeners/XYZ/ABC-Listener/Audit~2012-08-29T13:23:12.137+01:00~2012-08-29T13:23:12.136+01:00~~ESB/SYN2~<soap-env:Body xmlns:soap-env=< ?XML version="1.0" encoding="UTF-8" standalone="yes"?>
<XML xmlns="http:abc" v="1.0">
    <Main TTm="2011-06-02T13:22:51" BizDt="2011-06-02" TDt="2011-06-02" Cy="GBP" LPx="100.22" LQty="13" EID="89119611243" TTyp="0" TrStat="0" RptTyp="0" TrTyp="0" TID="CLG0000009182268">
        <Hdr SeqNum="1" Snt="2011-06-02T13:22:51" Tb="ABCMESSAGE" TD="ABC" SID="NCM" />
        <Pty R="56" ID="NCM"/>
        <Pty R="11" ID="ABC"/>
        <Instrmt Eh="WARM" SMeth="C" Mult="1250" PxmnMeth="1" MDt="2027-11-26" MY="202711" STp="MAT" PCmplx="FIN" Src="H" HID="STL261127001" Sm="IKL">
            <Pty R="22" ID="NCM"/>
</Main>

like this my log file will have 1000's of messages now in these mesages I need ot search and display in one line, all the highlighted elements along with the time in the out put line as:

29 Aug 2012 13:23:12 EID="89119611243" TID="CLG0000009182268" HID="STL261127001"

liek this in one line. This is I am looking for to diplay.

Thansk a lot.

Last edited by Corona688; 08-30-2012 at 01:14 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

Available design options for a cluster hosting many different virtualized Solaris versions

Good day, everyone, and thanks first off for reading my question. So, I have been Googling and reading oracle documentation for the past couple weeks, and I am just getting more and more confused as to what I need to do, and I would really appreciate some guidance or at least pointing me to... (4 Replies)
Discussion started by: Lyxix
4 Replies

2. UNIX for Dummies Questions & Answers

Exploring the grep options

Hi Folks, I have one query I have a log file to which I reach to putty and I open that particular log file in vi editor and search through /pattern, Suppose I have to search <ProgramId>627857272120951075</ProgramId> Then I have to open abc.log cd /var/log/ ls -ltr vi abc.log... (4 Replies)
Discussion started by: SankalpS
4 Replies

3. UNIX for Dummies Questions & Answers

Grep Options

Hi Folks, I have one query I have a log file to which I reach to putty and I open that particular log file in vi editor and search through /pattern, Suppose I have to search <ProgramId>627857272120951075</ProgramId> Then I have to open abc.log cd /var/log/ ls -ltr vi abc.log... (1 Reply)
Discussion started by: SankalpS
1 Replies

4. Solaris

lpadmin command options on solaris 10

lpadmin configuration issues on Solaris 10 Zone. I have configured a print queue using lpadmin command to print to print file server. Source server is a Solaris Zone running Solaris 10. Destination file print server is running OS AIX 5.3. I do not get errors when issuing the lp command to... (0 Replies)
Discussion started by: primeaup
0 Replies

5. Solaris

Solaris Single Sign on options

We are looking for implementing solaris single sign on with AD in our environment which as few hundred Solaris hosts and couple of hundred solaris zones ..IS there any third party software for the same or we can do it by just making the solaris servers as AD clients ? Any help is appreciated. (1 Reply)
Discussion started by: fugitive
1 Replies

6. UNIX for Advanced & Expert Users

Problem with grep command options in Sunsolaris

Hi Experts I need the following output from grep command of Sunsolaris on a set of input files. Output:........ 1st search string from file1 2nd search string from file1 3rd search string from file1 1st search string from file2 2nd search string from file2 3rd search string from... (3 Replies)
Discussion started by: ks_reddy
3 Replies

7. Shell Programming and Scripting

Grep options

Hi Team, I have a list of 12000 files and i am need to search for the names of the file which has long version numbers (say more than 5 decimals).. With the below instance u~15.1.4.1.2.1.5.1.5.1.24.1.24.1.5 lk-l~22.1.3.1.9.1.7.1.24.1.23 YDFVALLN.CPY~1 YEUPCASE.CPY~1 YFPRSTID.CPY~1... (2 Replies)
Discussion started by: ganga.dharan
2 Replies

8. Solaris

changing nfs options on Solaris 10

hi I changed nfs options in "/etc/auto_master": /net -hosts rw,bg,hard,nointr,rsize=32768,wsize=32768,tcp,ve rs=3,timeo=600,actimeo=0 then I did automount -v svcadm restart svc:/system/filesystem/autofs svcadm restart svc:/network/nfs/server:default When doing... (2 Replies)
Discussion started by: melanie_pfefer
2 Replies
Login or Register to Ask a Question