![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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 |
| 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 |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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"
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 |
|
|||
|
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 |
|||
| Google UNIX.COM |