LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 03-12-2010, 09:21 PM   #1
adamelody
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Rep: Reputation: 0
Accessing file, and manipulating with with folders


Hi!

I need help.

I have a .csv file with a list of Drugs Name that i need to remove from the folder. The folder consist of files that stored as drugname.mol format.

What i need to do is to sieve out those mol files from the folder?

How do i
(1) access the drugs names from the .csv file line by line (variable x)
(2) how do i access the files in the folder one by one (variable y)
(3) how can i do a comparison whether $x.mol == $y
(4) and shift them to another folder if $x.mol == $y


Hope u understand my questions, and thanks very much for the help.
 
Old 03-12-2010, 09:58 PM   #2
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
This may be a better question for the Programming forums as it sounds like you want to write a shell script. It does sound like it may be a simple shell script, something similar to this:
Code:
#!/bin/bash

cat file.csv | while read line; do  ##Read the csv file line by line
     SEARCH=`ls /path/with/mol/files | grep $line`  ##Search directory listing for the line read in the csv file
     if [ -n "$SEARCH" ] then  
          mv $y /path/of/new/folder ##If the SEARCH Variable is not null do this
     else
          do nothing ## If the SEARCH variable is null then do this
     fi
done
 
Old 03-12-2010, 10:29 PM   #3
adamelody
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Accessing file, and manipulating with with folders

Hi!

I need help.

I have a .csv file with a list of Drugs Name that i need to remove from the folder. The folder consist of files that stored as drugname.mol format.

What i need to do is to sieve out those mol files from the folder?

How do i
(1) access the drugs names from the .csv file line by line (variable x)
(2) how do i access the files in the folder one by one (variable y)
(3) how can i do a comparison whether $x.mol == $y
(4) and shift them to another folder if $x.mol == $y


is there any simple unix scripting that can be used? or maybe C, C++ or perl?


Hope u understand my questions, and thanks very much for the help.
 
Old 03-12-2010, 10:33 PM   #4
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
Sorry I just reread this code and it does a call to $y but $y has not been defined. Here is an update

Code:
#!/bin/bash

cat file.csv | while read line; do  ##Read the csv file line by line
     y=$line
     SEARCH=`ls /path/with/mol/files | grep $line`  ##Search directory listing for the line read in the csv file
     if [ -n "$SEARCH" ] then  
          mv $y /path/of/new/folder ##If the SEARCH Variable is not null do this
     else
          do nothing ## If the SEARCH variable is null then do this
     fi
done
 
1 members found this post helpful.
Old 03-13-2010, 03:16 AM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
What is in the csv file ? Is it just one column ? If so, you can just use a while read line loop and remove those that are not in the folder, or rather move the ones that you want into a different folder.

bash should work, unless you want something else.
 
Old 03-13-2010, 03:44 AM   #6
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
What about:

Code:
$ sudo rm -irf *.mol
in the directory that they (the .mol files) are in?
 
Old 03-13-2010, 08:55 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Hi adamelody

My first question is what have you tried?
If you need a direction I would suggest looking into tutorial pages on bash and / or awk.

If you have tried something and are stuck, then let us know where?

Otherwise it might be miscontrued that this is homework or an assignment you would like us to do for you
 
Old 03-13-2010, 09:20 AM   #8
adamelody
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Original Poster
Rep: Reputation: 0
thanks!!!! its solved!
 
Old 03-13-2010, 10:20 AM   #9
worm5252
Member
 
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567

Rep: Reputation: 57
No problem. Glad I could help you
 
Old 03-13-2010, 11:46 AM   #10
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 03-13-2010, 01:08 PM   #11
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I've merged your two duplicate threads---One thread per topic, pleas
 
Old 03-14-2010, 10:32 AM   #12
adamelody
LQ Newbie
 
Registered: Mar 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks. I have managed to solve it. manipulating files was alright, but i have no idea how to "move" the files.


Thanks for your help anyway!



Quote:
Originally Posted by grail View Post
Hi adamelody

My first question is what have you tried?
If you need a direction I would suggest looking into tutorial pages on bash and / or awk.

If you have tried something and are stuck, then let us know where?

Otherwise it might be miscontrued that this is homework or an assignment you would like us to do for you
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help manipulating a text file lt1776 Linux - Newbie 4 02-16-2010 11:11 AM
GPG - encode file while manipulating output file name itmozart Linux - Newbie 2 10-03-2009 12:28 PM
accessing shared folders tannu_ah Linux - Newbie 1 05-02-2009 04:19 PM
Accessing other users' folders malleat1 Linux - Newbie 3 12-12-2008 06:21 PM
Manipulating Fields Of Flat File Prasun1 General 10 09-29-2005 11:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:27 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration