Results 1 to 2 of 2

Thread: manipulateing files listed in text file

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default manipulateing files listed in text file

    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

    Im trying to work up a test script using this 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
    right now its viewing sort as the source not the destination $filename is not being read in

    Any help would be appreciated

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    hi,

    Code:
    while read filename
    do...
       cp "filename" sort/
       ...
    done <list.txt
    using bash mapfile
    Code:
    mapfile -t filenames <list.txt
    cp "${filename[@]}" sort/
    «A problem clearly stated is a problem half solved.»

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Solved] Shell script to convert log file into a csv formatted text file
    By c00l_chintu in forum Shell scripting
    Replies: 13
    Last Post: 28th September 2012, 12:24 AM
  2. Find various files from a text file
    By niiiro in forum CentOS / RHEL / Fedora
    Replies: 1
    Last Post: 8th March 2012, 06:40 PM
  3. [Solved] AWK printing all text after 3rd field in a text file
    By raj in forum Shell scripting
    Replies: 2
    Last Post: 3rd February 2012, 08:58 PM
  4. YUM install packages or groups listed in a file with space names in it
    By ashok1288 in forum CentOS / RHEL / Fedora
    Replies: 1
    Last Post: 29th June 2011, 10:02 PM
  5. Shell Script To change strings / text in a text file
    By jaysunn in forum Shell scripting
    Replies: 1
    Last Post: 8th May 2009, 05:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41