LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-25-2008, 08:25 AM   #1
adidassharma
LQ Newbie
 
Registered: Sep 2008
Posts: 15

Rep: Reputation: 0
searching for redundant patterns


Hi........
i hav n files lik this....

mat-1rvt_k.pdb-1ct1_f.pdb.txt
mat-1rvt_k.pdb-1rvt_k.pdb.txt
mat-2cml_c.pdb-1uxb_c.pdb.txt
mat-2cml_c.pdb-2cml_c.pdb.txt

if the same pdb's are present, then i want to delete the file......
i mean if mat-1rvt_k.pdb-1rvt_k.pdb.txt is present then i want to delete this file......similarly for n files, i want to check the redundant patterns and delet them .....
 
Old 09-25-2008, 10:14 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 239Reputation: 239Reputation: 239
rm *rvt_k*rvt_k
 
Old 09-25-2008, 07:28 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
This will match the repeated patterns. For test purposes it just notes the match. you can easily adapt it to delete files.

Code:
for rec in `cat t.t`
do
    first=`echo $rec |cut -d'-' -f2`
    second=`echo $rec |cut -d'-' -f3 |cut -d'.' -f1,2`
#   echo $first $second # debug check
    if [[ $first = $second ]]
    then
        echo match: delete $rec
    fi
done
 
Old 09-25-2008, 11:08 PM   #4
adidassharma
LQ Newbie
 
Registered: Sep 2008
Posts: 15

Original Poster
Rep: Reputation: 0
wat u hav given is for one file......but i have n files.....anyways thanq....i figured it out myself....the code is

echo mat-1rvt_k.pdb-1hgg_d.pdb.txt | cut -f2 -d'-' > a
echo mat-1rvt_k.pdb-1hgg_d.pdb.txt | cut -f3 -d'-' | cut -f1,2 -d'.' > b

c1="`cat a`"
echo "$c1"
c2="`cat b`"
echo "$c2"

if [[ `echo "$c1"` = `echo "$c2"` ]]
then
rm -f mat-1rvt_k.pdb-1hgg_d.pdb.txt
fi

NOTE:####THIS IS FOR ONLY ONE FILE.....I USED FOR LOOP FOR N FILES AND APPENDED THE VALUES OF C1 AND C2 ##########
 
Old 09-25-2008, 11:10 PM   #5
adidassharma
LQ Newbie
 
Registered: Sep 2008
Posts: 15

Original Poster
Rep: Reputation: 0
many thanks chrism......wat was bugging me is variable assigning....i used the same logic as u have, but i was giving if $a -eq $b....thus was havin some syntax error.....

Thanks......once agn
 
Old 09-26-2008, 12:35 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5
Posts: 16,086

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
For multiple files, change my first line:

Code:
for rec in `cat t.t`

to

for rec in `cat <filepattern>`

eg 

for rec in `cat *.txt`
or add an outer loop and feed filename to my code as inner loop
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Patterns som_kurian Programming 13 12-06-2007 09:01 AM
Uses for a redundant P3 machine? LDJ Linux - General 7 09-11-2006 10:18 AM
Redundant servers dranobob Linux - General 3 04-03-2006 02:59 PM
Remembering patterns and printing only those patterns using sed bernie82 Programming 5 05-26-2005 05:18 PM
Searching patterns from file MichaelVaughn Programming 1 04-06-2004 11:18 AM


All times are GMT -5. The time now is 08:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration