If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > seting variable = to value from .txt / cp with variable as argument

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Nov 2012
Posts: 1
seting variable = to value from .txt / cp with variable as argument

I am trying to write a script that will copy all file listed in a text file (100s of file names) to a new directory each time I run it
Essentially i wanna pick out certain files from a large collection to form a smaller on

Im trying to work up a test script using this scaled down model

Assume the script will run with main as current working directory and I know how many files/lines will be in List.txt

Contents of main
script.sh
sort < is a folder
List.txt
stuff.pdf
misc.rtf
junk.txt
thing.txt

Contents of List.txt
stuff.pdf
misc.rtf
thing.txt

Script so far (contests of script.sh)
#1/bin/bash

count =0
while [ $count -le 3 ]
do
filename= sed -n '1p' List
cp $filename sort
count=$(($count + 1 ))
done

Problems
(1)
count though lines with counter
something like
filename= sed -n '$countp' List

Im open to useing a different command here cat or whatever
but I want it to take the value from $count and grab whatevers is on the coresponding line in List.txt and store the result in a variable


(2)
use the file name stored in $filename in copy command
currenty gives error "cp: missing destination file operand after 'sort'"
I know this means its not reading the file name from $filename and is using sort as target not the destination but I dunno how to fix.

Any help would be appreciated
Reply With Quote
  #2 (permalink)  
Old
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 5,333
Something like this?
Code:
head -3 List.txt | while read F; do test -f $F && cp $F sort/; done
__________________
---
"It does not work" is not a valid problem statement.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,622
Quote:
Originally Posted by IAmTheGrass View Post
I am trying to write a script that will copy all file listed in a text file
. . . Etc . . .
(1)
count though lines with counter . . .

(2)
use the file name stored in $filename in copy command . . .

Any help would be appreciated
(1) Why do you need to count?
(2) Try this:
Code:
cat list.txt|xargs -i! cp ! sort/
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
Pingbacks are On
Refbacks are On