grep options in solaris


 
Thread Tools Search this Thread
Operating Systems Solaris grep options in solaris
# 8  
Old 08-30-2012
Quote:
Originally Posted by sudha143
There is no link Rangarasan. it is disabled.
https://www.unix.com/how-post-unix-li...code-tags.html
# 9  
Old 08-30-2012
This video is not opening for me in office.

Please help on my query, I will read the usage of code tags and will post with this in my next post.

bit urgent pls.
# 10  
Old 08-30-2012
Processing XML isn't trivial, grep can't do it. grep handles lines.

Handling XML and non-XML simultaneously is outright odd.

I think I've found a way to at least make your data suitable for an XML parser...

Code:
# Convert mixed xml and non-xml lines into pure XML
$ awk '/INFO/ { sub(/\[/, "", $3); sub(/\]/, "", $6);
        printf("<entry date=\"%s.%s.%s.%s\">\n", $3, $4, $5, $6); next }
        /[/]Main/ { print $0"</entry>" ; next } 1' < log.almostxml

<entry date="29.Aug.2012.13:23:12">
<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></entry>
<entry date="29.Aug.2012.13:23:12">
<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></entry>
<entry date="29.Aug.2012.13:23:12">
<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></entry>
<entry date="29.Aug.2012.13:23:12">
<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></entry>
<entry date="29.Aug.2012.13:23:12">
<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></entry>

$

# 11  
Old 08-30-2012
Code:
$ cat xmlj.awk
BEGIN { # Handle filters
        split(FILTER, F);
        for(N=1; N in F; N++)   F[F[N]]=1

        RS="<"; FS=">"; OFS="\t"; O=0
        if(!CDEP) CDEP=2;
}

function splitarg(IN, OUT) # Turn data="this" into 'data' and 'this'
{
        sub(/[/]$/, "", IN);    # Clear out / from self-closing tags
        split(IN, OUT, "=");
        if(OUT[2] ~ /^['"].*[."][/]?$/)
                OUT[2]=substr(OUT[2], 2, length(OUT[2])-2);

        OUT[1]=tolower(OUT[1]);
}

function chomp(DATA) # Remove preceding and trailing whitespace
{
        sub(/^[ \r\n\t]+/, "", DATA);
        sub(/[ \r\n\t]+$/, "", DATA);
        return(DATA);
}

function doindex(ARG, A) # Add data to array for printing
{
        splitarg(ARG, A);
        I=DEP ":" STACK[DEP] "." A[1]
        if(!ORDER[I])
        {
                ORDER[++O]=I;   ORDER[I]=1
                if(!FILTER)     F[STACK[DEP] "." A[1]]=1
        }

        DATA[I]=A[2];
}

# Handle improper nesting or non-autoclosed tags
function closetag(TAG)
{
        for(X=DEP; X>0; X--)    if(STACK[X] == TAG) break;
        if(X > 0)       DEP=X-1;
}

/^\?/ || /^$/   {       next    } # Skip XML specification or blank records

{
        TAG=chomp($1);          CDATA=chomp($2);
        # Split apart tag arguments, if any
        FS=" "; $0=TAG; TAG=tolower($1); FS=">"

        # Close tags
        if(substr(TAG, 1, 1) == "/")
        {
                TAG=substr(TAG,2,length(TAG)-1);
                CLOSE++;
                closetag(TAG);
        }
        else # Open tag or self-closing tag
        {
                STACK[++DEP]=TAG;
                for(N=2; N<=NF; N++)    doindex($N);
                if(CDATA) doindex("[CDATA]='" CDATA "'");
                CLOSE=0;
        }

        # Self-closing tags
        if($NF ~ /[/]$/)        DEP--;

}

CLOSE >= CDEP {
        # If we expect 2 close tags and get 5, still only print once
        if(CLOSE > CDEP)        next

        if(! HEADER++)
        {
                $0="";
                for(M=N=1; M<=O; M++)
                {
                        split(ORDER[M], A, ":");
                        if(A[2] in F) $(N++)=A[2];
                }
                print;
        }

        $0="";
        for(M=N=1; M<=O; M++)
        {
                split(ORDER[M], A, ":");
                if(A[2] in F) $(N++)=DATA[ORDER[M]]
        }
        print
}

$  awk '/INFO/ {
                sub(/\[/, "", $3); sub(/\]/, "", $6);
                printf("<entry date=\"%s.%s.%s.%s\">\n", $3, $4, $5, $6); next }
        /[/]Main/ { print $0"</entry>" ; next } 1' < log.almostxml |
        awk -v FILTER="entry.date main.tid main.eid instrmt.hid" -f xmlj.awk HEADER=1

29.Aug.2012.13:23:12    89119611243     CLG0000009182268        STL261127001
29.Aug.2012.13:23:12    89119611243     CLG0000009182268        STL261127001
29.Aug.2012.13:23:12    89119611243     CLG0000009182268        STL261127001
29.Aug.2012.13:23:12    89119611243     CLG0000009182268        STL261127001
29.Aug.2012.13:23:12    89119611243     CLG0000009182268        STL261127001

$

Use nawk on solaris.

Last edited by Corona688; 08-30-2012 at 04:37 PM..
This User Gave Thanks to Corona688 For This Post:
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