Grep - Reporting help...

I have a file that I need to clean up and reformat and I thought maybe I could right a script for this. Below is what the data looks like:

ACCESSORID = UFLSCLC NAME = TOM JONES
PROFILES = PHVPWTR2

ACCESSORID = UFLSDAM NAME = MIKE JONES
PROFILES = PHVPWTR2

ACCESSORID = UFLSDNM NAME = BOB SMITH
PROFILES = PXMDWTAM PHVPWTR5 PHVPBOS7

PROFILES = PHVPWTBC PHVPBOS8

ACCESSORID = UFLSEAL NAME = TOM SMITH
PROFILES = PHVPWTR2

The output that I need is this:

UFLSCLC PHVPWTR2
UFLSDAM PHVPWTR2
UFLSDMN PXMDWTAM
UFLSDMN PHVPWTR5
UFLSDMN PHVPBOS7
UHVPDMN PHVPWTBC
UHVPDMN PHVPBOS8
UFLSEAL PHVPWTR2

Is this hard to do? Any ideas what this script would look like?

Thanks!

You have two questions:

  1. Is this hard to do?
    Answer: that depends on the person, the language used, etc.

  2. Any ideas what this script would look like?
    Answer: Yes.

I am however afraid that your next question will be: Can you give me that same look? So here it is:

#!/bin/bash

while read TYPE EQSIGN RESTOFLINE
do      case ${TYPE} in
        ACCESSORID)
                ACC="${RESTOFLINE%% *}"
                ;;
        PROFILES)
                for PROFILE in ${RESTOFLINE}
                do      echo "${ACC} ${PROFILE}"
                done
                ;;
        esac
done <data

It supposes that your input file is in the same dirctory and has the name “data” (look at the last line of the sript where you can change this). I copied your input to make *data *and when I run it I get:

henk@boven:~/lll> ./locomars
UFLSCLC PHVPWTR2
UFLSDAM PHVPWTR2
UFLSDNM PXMDWTAM
UFLSDNM PHVPWTR5
UFLSDNM PHVPBOS7
UFLSDNM PHVPWTBC
UFLSDNM PHVPBOS8
UFLSEAL PHVPWTR2
henk@boven:~/lll>

I hope this is what you want.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Because I’m not the best w/SED I haven’t managed to combine these all
together, but it gets you close:

sed -r ‘s/(.+?)NAME.+/\1/’ ./test0.txt | sed -e :a -e ‘$!N; s/
/ /; ta’ |
sed -r ‘s/ACCESSORID\s+=\s+/
/g’ | sed -r ‘s/PROFILES\s+=\s+//g’ | sed -r
‘s/\s+/ /g’ | grep -E -v ‘^$’

Now if only you could take output like this:

UFLSCLC PHVPWTR2
UFLSDAM PHVPWTR2
UFLSDNM PXMDWTAM PHVPWTR5 PHVPBOS7 PHVPWTBC PHVPBOS8
UFLSEAL PHVPWTR2

Still working on splitting up the duplicates.

Good luck.

lcomars wrote:
> I have a file that I need to clean up and reformat and I thought maybe I
> could right a script for this. Below is what the data looks like:
>
> ACCESSORID = UFLSCLC NAME = TOM JONES
> PROFILES = PHVPWTR2
>
>
>
> ACCESSORID = UFLSDAM NAME = MIKE JONES
> PROFILES = PHVPWTR2
>
>
>
> ACCESSORID = UFLSDNM NAME = BOB SMITH
> PROFILES = PXMDWTAM PHVPWTR5 PHVPBOS7
>
> PROFILES = PHVPWTBC PHVPBOS8
>
>
>
> ACCESSORID = UFLSEAL NAME = TOM SMITH
> PROFILES = PHVPWTR2
>
> The output that I need is this:
>
> UFLSCLC PHVPWTR2
> UFLSDAM PHVPWTR2
> UFLSDMN PXMDWTAM
> UFLSDMN PHVPWTR5
> UFLSDMN PHVPBOS7
> UHVPDMN PHVPWTBC
> UHVPDMN PHVPBOS8
> UFLSEAL PHVPWTR2
>
> Is this hard to do? Any ideas what this script would look like?
>
> Thanks!
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJJzM+oAAoJEF+XTK08PnB5TH8QAMHJoGAnl+SinXPxAGtnDZwx
0TXHiDLb8hNLWSEgcae9wQ6sUNFvdy7sM+o9Xv40bKdD4twQtHNhqAZ0Qnp+/wi4
JQHiDcXIK5c+aEWzSsaGi0fanS4uqFYcqKmmhZBqEf9caIl2LxIbdkbGulSI1ER2
PmLpg/ij1vCTxPr5xk0qzQTKXo3XE79lvu9lNkR8v7RlPxVNikbuWv3SxSDknCJi
/g+mNsn0K+1hh1NtD0WJkXVIEU7Qr0IM9/ZXtl/VfpkqiEiMRLCKLgFeaxNYPy4U
xT7r2zsJuQdf9C9unAYrvGpfZk3lGdjtWm4N1+lvi3RBoq2qbgz6JOfG6ICi7epR
CEny8WCcVThs5SR3CX/YYbwwMGihY0641Kd6xOLm7RSYPPUhWWiWg0Gq2Z4bHdoA
VEwt39pGTuys1q8nFfnE29HnFzoJWuREVH61sf5FrcHskrK3CX98F7ncJvIP+6JK
WG+YYG2PkDhWqtY4a/i3UYHVyeSx/v+gwKkpXN0W7n3VataNQZLHL6V5lBalzX/F
76wgXqk9Aym/r0ZzD+q3WfMj1GVynyjfW2hWXWtQRgHHqcAvDz8dHasSvH5oGFuV
vq5ui/GZmWGr6bb4qshk6LijJQ2pRpE3UdqRPTjut5HjveUZ1hQ1+oz7GP7Qmgtx
6Xc9lvLwl2n1PF87fBhA
=dwdk
-----END PGP SIGNATURE-----

Thank you very much to everyone that helped me out with this. This is exactly what I was looking for. Thanks again.