Operating System - HP-UX
1763035 Members
2884 Online
108909 Solutions
New Discussion юеВ

info in required format from a file

 
SOLVED
Go to solution
kam_6
New Member

info in required format from a file

have a file which is of the format :-

/Ixxxxxx/WORK/HANDOFF;/xxxxxx/WORK/MB_BACKUP;;;\\\\CAICMESF002DATA_GR
P\OPERATIONS\IBBSSPOOLS\HANDOFF\;ACHOFF*;achoff;binary;3;1;ACHOFF.zi
p;0;1;0;

I want to grep all capital and small OFF pattern in a format :-

/Ixxxxxx/WORK/HANDOFF | ACHOFF* | achoff | ACHOFF.zip | ( 12th field ie 1 Or 0 )

I have tried the following command :-
cat filename |grep -i off |awk -F ";" '{print $1,$6,$7,$12}'

but I am not gettin the desired output
5 REPLIES 5
RAC_1
Honored Contributor

Re: info in required format from a file

cat filename |grep -i off |awk -F ";" '{print $1,"|"$6,"|"$7,"|"$NF}'

Anil
There is no substitute to HARDWORK
OldSchool
Honored Contributor

Re: info in required format from a file

given the sample you provided, try this:

cat filename | grep -i off | awk -F";" '{OFS="|"; print $1,$6,$7,$11,$12}'

This changes the Output File Separator to "|" and produces:

/xxxxxx/WORK/HANDOFF|ACHOFF*|achoff|ACHOFF.zip|0

Hope this helps.....
Arturo Galbiati
Esteemed Contributor

Re: info in required format from a file

you can use only awk:
awk -F; '/OFF/||/off/ {print $1 "|" $6 "|" $7 "|"$NF}' filename

HTH,
Art
H.Merijn Brand (procura
Honored Contributor
Solution

Re: info in required format from a file

Or switch to perl

# perl -nle'/off/i&&print join"|",(split/;/)[0,5,6,10,11]' filename
/Ixxxxxx/WORK/HANDOFF|ACHOFF*|achoff|ACHOFF.zip|0

or using autosplit

# perl -aF\; -nle'/off/i&&print join"|",@F[0,5,6,10,11]' filename
/Ixxxxxx/WORK/HANDOFF|ACHOFF*|achoff|ACHOFF.zip|0

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
kam_6
New Member

Re: info in required format from a file

Thanks !!