Accessing file, and manipulating with with folders
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.