The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-16-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
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.
Reply With Quote
Forum Sponsor
  #2  
Old 01-16-2008
in2nix4life's Avatar
Registered User
 

Join Date: Oct 2007
Location: East Coast
Posts: 46
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
Reply With Quote
  #3  
Old 01-16-2008
in2nix4life's Avatar
Registered User
 

Join Date: Oct 2007
Location: East Coast
Posts: 46
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'
Reply With Quote
  #4  
Old 01-17-2008
Registered User
 

Join Date: Jan 2008
Posts: 2
Thanks,
I will try it.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 01:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0