shell - Create directories by reading file as a input in bash -
i have input file temp.txt content following
2013-08-13 /data/psg/lz/inventory_forecast/load_date=2013-03-01 2013-08-14 /data/psg/lz/inventory_forecast/load_date=2013-03-02 2013-08-15 /data/psg/lz/inventory_forecast/load_date=2013-03-03 2013-07-30 /data/psg/lz/inventory_forecast/load_date=2013-07-30 2013-07-31 /data/psg/lz/inventory_forecast/load_date=2013-07-31 2013-08-16 /data/psg/lz/inventory_forecast/load_date=2013-08-13
i need iterate on file , create directories date specified @ begining of line , move data in directory specified after date particular directory..
for example: first line need
mkdir "2013-08-13"
and then
mv /data/psg/lz/inventory_forecast/load_date=2013-03-01/ 2013-08-13
i trying
cat temp.txt | while read line ; mkdir "echo $line | awk '{print $0}'"; done;
tried use line array using
cat temp.txt | while read line; linearray=($line) echo $line, ${linearray[0]}, $linearray[1]; done;
but none of these seem work.. idea how approach problem ?
you can read lines 2 variables. example:
while read -r date path # reads lines of temp.txt 1 one, # , sets first word variable "date", # , remaining words variable "path" mkdir -p -- "$date" # creates directory named "$date". mv -- "$path" "$date" # moves file "$path" variable "$date folder" done < temp.txt # here set input of while loop temp.txt file
the --
option used if file starts -
not interpreted option, treated literally.
the -p
or --parents
makes mkdir
command not trow error if directory exists, , make parent directories if necessary.
Comments
Post a Comment