1835844 Members
2608 Online
110085 Solutions
New Discussion

need some scripting help

 
Mark Harshman_1
Regular Advisor

need some scripting help

i need a simple script to read a file that contains one field. The field is a list of files in a directory. As i read in these files..i want to move each one to a different directory. Sure this is easy..but my scripting knowledge is zilch...

thanks
Never underestimate the power of stupid people in large groups
4 REPLIES 4
Sundar_7
Honored Contributor

Re: need some scripting help

Hi Mark,

You can try something like this

# vi /usr/local/bin/flist
/source/dir/file1
/source/dir/file2
/source/dir/file3
#
# export TARGET_DIR=/target/dir
# FAILED=0
# for FILE_NAME in $(cat /usr/local/bin/flist)
do
mv $FILE_NAME $TARGET_DIR/
[ $? -ne 0 ] && FAILED=1
done
#
# [ $FAILED -eq 0 ] && echo "Move successful" || echo "Move unsuccessful"
Learn What to do ,How to do and more importantly When to do ?
Sanjay_6
Honored Contributor

Re: need some scripting help

Hi,

Is this what you want to do.

source_dir=/test
dest_dir=/test
all files in /test that has *.org extn, you want to move to /test1.

you can do this from the command line

pwd
/test
# for i in `ls -l *.org |awk '{print $9}'`
>do
>mv $i /test1
>done

Hope this helps.

Regds

Steven E. Protter
Exalted Contributor

Re: need some scripting help

Possible improvement in efficiency

Change:
for i in `ls -l *.org |awk '{print $9}'`

to

for i in `ls -1 *.org`

Changes ls -l "el"

to ls -1 "one"

Saves the awk processing. Probably a meaningless improvement.

Nice job itrc colleagues.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Leif Halvarsson_2
Honored Contributor

Re: need some scripting help

Hi,

Hope I understand you correct. You have a list of files, all in the same directory and want to move to a different directory.


while read file
do
mv $file //$(basename $file)
done