![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to parse through a file and based on condition form another output file | sivasu.india | UNIX for Advanced & Expert Users | 6 | 02-28-2008 01:59 AM |
| Parse XML file | viki | Shell Programming and Scripting | 5 | 04-13-2007 01:25 AM |
| Parse file | sbasetty | Shell Programming and Scripting | 5 | 03-27-2007 10:27 AM |
| How to parse a XML file using PERL and XML::DOm | girigopal | Shell Programming and Scripting | 0 | 06-27-2005 03:46 AM |
| using getopt to parse a file | coolguyshail | Shell Programming and Scripting | 1 | 06-08-2005 03:58 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help to parse the file
# Start
"ABC" SFFd 0 4 [abc] Time SFFT 4 8 {Sec} [abc] User SFFTimeVal 12 8 {Sec} [asd] # Start "CP" SFFT (Time") {Sec} [fgh] Time" SFFT ("Utn") {Sec} [jhk] I have bundle of file in above format. please help me to create a shell script that will take input of file name and output will be like this. ABC,SFFd Time,SFFT,sec User,SFFTimeVal,sec CP,SFFT,sec Time,SFFT,sec I don't want to add those row which is commented with # sign Thanks in Advance. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
This may help get you started:
BEFORE: cat file-1.txt # Start "ABC" SFFd 0 4 [abc] Time SFFT 4 8 {Sec} [abc] User SFFTimeVal 12 8 {Sec} [asd] AFTER: cat file-1.txt | grep -v ^# | sed -e 's/"//g' | awk '{print $1","$2",sec"}' ABC,SFFd,sec Time,SFFT,sec User,SFFTimeVal,sec |
|
#3
|
||||
|
||||
|
Alternatively, in Perl:
#!/usr/bin/perl while(<>) { chomp; s/^\#.*//g; s/"//g; s/{|}//g; s/\(.*\)//g; s/\[.*\]//g; s/\d*//g; s/Sec/sec/g; s/\s+/,/g; s/^\s+$//g; chop; print "$_\n" unless(/^$/); } Run as 'parsefile.pl file.txt' |
|
#4
|
|||
|
|||
|
Thanks,
I will try it. |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|