Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old March 11th, 2007, 01:53 AM
ovince ovince is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 14 ovince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 33 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old March 11th, 2007, 04:25 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,196 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 13 h 42 m 7 sec
Reputation Power: 252
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

Reply With Quote
  #3  
Old March 11th, 2007, 05:46 AM
ovince ovince is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 14 ovince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 33 sec
Reputation Power: 0
thans for reply

this change in the program does not the filtering job. Have an idea why?

Reply With Quote
  #4  
Old March 11th, 2007, 06:55 AM
ovince ovince is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 14 ovince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 39 m 33 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Filtering


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway