January 04, 2009

UNIX case study - 9

Extract fields


please see the logs shown below:

12-12 08:47:37.545 DBG AGIML SERVER[1]..............................write() (
TOPUP
999
97735754501317BPL1229051853686229
)

Now i want to write a script which will extract the fields like this

TOPUP,9773575450,1317,BPL,1

these are the fields shown in the different tags.

And one thing more the fields between the tag ............,
it is taking it a single column of log.

example less file | grep "9773575450"
will display the whole line.

http://www.unix.com/shell-programming-scripting/93722-script-extract-fields.html

1 comment:

  1. Anonymous7:26 AM

    sed '
    s/.*agiml// # remove up to agiml
    s|/agiml.*|| # remove /agiml to end of line
    s/<[^>]*>/,/g # convert tags to commas
    s/,,*/,/g # compress multiple commas to a single comma
    s/^,// # remove leading comma
    s/,$// # remove trailing comma
    ' FILE

    ReplyDelete

Note: Only a member of this blog may post a comment.