![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To extract everything between two delimiters | dowsed4u8 | SUN Solaris | 1 | 01-16-2008 02:49 PM |
| parse multiple lines? should be a easy answer... | DeuceLee | UNIX for Dummies Questions & Answers | 4 | 01-04-2008 04:54 PM |
| Delimiters missing | Indalecio | Shell Programming and Scripting | 2 | 02-23-2007 04:28 AM |
| Cut based on Two Delimiters at one go | pbsrinivas | Shell Programming and Scripting | 4 | 01-18-2007 04:45 AM |
| awk - treat multiple delimiters as one | peter.herlihy | Shell Programming and Scripting | 6 | 08-30-2002 01:12 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
parse of lines with different delimiters
Hi,
I am having huge file with the following lines. 2007:10:01:00:00:49:GMT: subject=BMRA.BM.T_ABTH7.FPN, message={SD=2007:10:01:00:00:00:GMT,SP=5,NP=2,TS=2007:10:01:01:00:00:GMT,VP=0.0,TS=2007:10:01:01:30: 00:GMT,VP=0.0} 2007:10:01:00:00:49:GMT: subject=BMRA.BM.T_ABTH7G.FPN, message={SD=2007:10:01:00:00:00:GMT,SP=5,NP=2,TS=2007:10:01:01:00:00:GMT,VP=0.0,TS=2007:10:01:01:30: 00:GMT,VP=0.0} I need to parse them into the following format. 2007-10-01,T_ABTH7,2007-10-0100:00:00,5,0.0 2007-10-01,T_ABTH7G,2007-10-0100:00:00,5,0.0 Is there a way to parse the entire file without reading a single line of file and formating the output. Thanks in advance. |
|
||||
|
Hi Penchal,
I want to parse the highlighted values. 2007:10:01:00:00:49:GMT: subject=BMRA.BM.T_ABTH7.FPN, message={SD=2007:10:01:00:00:00:GMT,SP=5,NP=2,TS=2007:10:01:01:00:00:GMT,VP=0.0,TS=2007:10:01:01:30: 00:GMT,VP=0.0} First output column (2007-10-01): SD=2007:10:01:00:00:00 Second column (T_ABTH7): subject=BMRA.BM.T_ABTH7.FPN Third Column (2007-10-0100:00:00): TS=2007:10:01:01:00:00 Fourth Column (5): SP=5 Fifth Column(0.0) : VP=0.0 Output for a single line : 2007-10-01,T_ABTH7,2007-10-0100:00:00,5,0.0 Please let me know if this clear. |
|
||||
|
Solution with gawk:
Code:
#!/usr/bin/awk -f
BEGIN {FS=","; OFS=","}
{
print \
gensub(/^.+([0-9][0-9][0-9][0-9]:[0-9][0-9]:[0-9][0-9]).+$/, "\\1", 1, $2),
gensub(/^.+subject=BMRA.BM.(.+).FPN/, "\\1", 1, $1),
gensub(/^TS=(.+):GMT/, "\\1", 1, $5),
gensub(/^SP=(.+)/, "\\1", 1, $3),
gensub(/^VP=(.+)/, "\\1", 1, $6)
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|