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
reading .bin files eastcoast_uix UNIX for Dummies Questions & Answers 1 06-26-2007 10:43 AM
reading gz files arushunter Shell Programming and Scripting 2 02-16-2007 02:29 PM
Reading *.chm files? riwa UNIX for Dummies Questions & Answers 3 04-02-2006 06:30 PM
moving files from a unix directory to a windows directory gleads UNIX for Dummies Questions & Answers 2 08-29-2002 05:42 PM
reading directory for most recent file? duncan_glover UNIX for Dummies Questions & Answers 3 08-22-2002 04:26 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-31-2007
Registered User
 

Join Date: Jul 2006
Posts: 47
Arrow Reading files in directory

Hi Everyone , have a nice day
i need a help on this thing
algo is something like
in certain path like /root/user1
i have many files , i need a code which could open every file one by one and then
each file has contents like this

<moid>CcnCounters=CAPv3-Received-Total-Requests, Source = Proc_m0_s23</moid>
<r>1100</r>
<sf>FALSE</sf></mv><mv>
<moid>CcnCounters=CAPv3-Received-Total-Requests, Source = _SYSTEM</moid>
<r>2196</r>
<sf>FALSE</sf></mv><mv>
<moid>CcnCounters=CAPv3-Sent-Total-Requests, Source = Proc_m0_s23</moid>
<r>1239</r>
<sf>FALSE</sf></mv><mv>
<moid>CcnCounters=CAPv3-Sent-Total-Requests, Source = _SYSTEM</moid>
<r>2463</r>
<sf>FALSE</sf></mv><mv>
<moid>CcnCounters=CAPv3-Sent-Total-Requests, Source = Proc_m0_s21</moid>
<r>1224</r>


and it should extract information between <moid> and </moid> and between <r> and </r>
as you can have idea <moid> has a counter name and <r> has counter value
so it should extract this from every file and keep on appending it in an output file like this

counter name counter value
counter name counter value
.................. ..................

untill it gets done with all files in /root/user1

Thanks in Anticipation and Regards
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-31-2007
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,181
I suggest you do this in PERL.
Reply With Quote
  #3 (permalink)  
Old 08-31-2007
Registered User
 

Join Date: Sep 2006
Posts: 1,423
only for one file. i leave it to you to do multiple files.
Code:
awk '/moid/{ gsub("<moid>|</moid>","");moid[c++]=$0}
    /<r>/{ gsub("<r>|</r>","");r[d++]=$0}
END{
  for(i=0;i<=c;i++) {
	print moid[i] " " r[i]
  }
}' "file"
output:
Code:
./test.sh
CcnCounters=CAPv3-Received-Total-Requests, Source = Proc_m0_s23 1100
CcnCounters=CAPv3-Received-Total-Requests, Source = _SYSTEM 2196
CcnCounters=CAPv3-Sent-Total-Requests, Source = Proc_m0_s23 1239
CcnCounters=CAPv3-Sent-Total-Requests, Source = _SYSTEM 2463
CcnCounters=CAPv3-Sent-Total-Requests, Source = Proc_m0_s21 1224
Reply With Quote
  #4 (permalink)  
Old 09-04-2007
Registered User
 

Join Date: Jun 2007
Posts: 73
Try this!!!!!!!!!!!!!!!


sed 's/\(<moid>\)\(.*\)\(<\/moid>\)/\2/g' input file | cut -d"<" -f1 >countersource.txt


sed 's/\(<r>\)\(.*\)\(<\/r>\)/\2/g' input file |grep "[0-9]" |sed 's/\(<moid>\)\(.*\)\(<\/moid>\)\(.*\)/\4/g' >countername.txt
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:37 AM.


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

Content Relevant URLs by vBSEO 3.2.0