|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Filtering
Hi All,
I should take all "more*.dat" files from each "DH*" directory and to write out first 5 rows into "list" fajl. So each "DH*" directory should have "list" falj with 5 rows from all "more*.dat" within it. This command line works this job for dir in DH* ; do for file in `find $dir -type f -name "more*data.dat" -print`; do awk 'BEGIN{FS=","}{if(NR>1 && NR<7){ f=n=FILENAME;sub(/[^/]+$/,"list",f);sub(/.*\//,"",n);print $6,$7,n>>f}}' $file done done But I would NOT like to have file names in "list" that contain words "t10" or "t9". How to filter them out in this context? Thank you Oliver |
|
#2
|
|||
|
|||
|
Firstly you code will be much easier to read if you post it between 'code' tags so it preserves the layout, like this:
Code:
for dir in DH* ; do
for file in `find $dir -type f -name "more*data.dat" -print`; do
awk 'BEGIN{FS=","}{if(NR>1 && NR<7){
f=n=FILENAME;sub(/[^/]+$/,"list",f);sub(/.*\//,"",n);print
$6,$7,n>>f}}' $file
done
done
Awk will let you filter out lines that match a regex, so I think this will do what you want (I have also changed the formatting to make it more readable): Code:
for dir in DH* ; do
for file in `find $dir -type f -name "more*data.dat" -print`; do
awk '
BEGIN{FS=","}
!/t(9|10)/ {
if(NR>1 && NR<7){
f=n=FILENAME;
sub(/[^/]+$/,"list",f);
sub(/.*\//,"",n);
print $6,$7,n>>f
}
}
' $file
done
done
Last edited by DevCoach : March 11th, 2007 at 04:26 AM. Reason: typo |
|
#3
|
|||
|
|||
|
thans for reply
this change in the program does not the filtering job. Have an idea why? |
|
#4
|
|||
|
|||
|
ok. this is what I wanted....but your suggestion direct me to it
for dir in DH* ; do for file in `find $dir -type f -name "more*data.dat" -print`; do awk ' BEGIN{FS=","} !/t(9|10)/ { if(NR>1 && NR<7){ f=n=FILENAME; sub(/[^/]+$/,"list",f); sub(/.*\//,"",n); if (match(n,/tau(1|2)/) == 0) print $6,$7,n>>f } } ' $file done done |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Other Programming Languages > Filtering |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|