Find the answer to your Linux question:
Results 1 to 2 of 2
Hi All, I am new to Unix scripting, I have requirement where I need to read the key value pair from config file. Sample Config file: Key(File Pattern) Value(File Directory ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Posts
    1

    Help related to Script to move files depending on config values


    Hi All,

    I am new to Unix scripting, I have requirement where I need to read the key value pair from config file.
    Sample Config file:
    Key(File Pattern) Value(File Directory location)
    test /Users/Bkumar/Downloads/testdir
    prod /Users/Bkumar/Downloads/proddir

    Now I need to write a unix script(bash)
    1) To read the key value pairs
    2) After fetching key value pair , we need to search in the source(ex Source Dir) directory if there are any matches to the key, if yes then we need move the files to destination directory(present in value Ex testdir ) .

    If any one have done this kind of script please do the needful.

    Thanks,
    Bhanu

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Location
    Western Kentucky
    Posts
    626
    Hint:
    Code:
    LIST=/some/config/file
    SRC_DIR=/some/src/directory
    DST_DIR=/some/dst/directory
    
    for name in `cat $LIST`;do
    ls $SRC_DIR | grep $name | while read line; do mv ${line} $DST_DIR
    done
    done
    linux user # 503963

Posting Permissions

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