linux - how to do 'ls -lrt' of data from a input file -
i have input file file.csv
(data separated comma delimiter) have 3 comma-delimited rows. data file names.
e.g:
test,test1,test2,test3,,n a,b,c,d,,n p,q,r,s,,n
now, have requirement first row of file file.csv
data exist or not in directory abc
command ls -lrt
. output of command should redirected text file a.txt
.
e.g:
ls -lrt test ls -lrt test1 ....
next: second row of file.csv
data in directory abc
command ls -lrt
. output of command should appended text file a.txt
.
e.g:
ls -lrt ls -lrt b ....
next: third row of file.csv
data in directory xyz
command ls -lrt
. output of command should appended text file a.txt
.
e.g:
ls -lrt p ls -lrt q ....
sample output:
-rw-r--r-- 1 dba dba 122 jan 21 06:44 test ls: p: no such file or directory
how can achieve this?
something maybe:
dirs=(abc abc xyz) index=1 while read -r line; ifs=, f in $line; ls -lrt "${dirs[$index]}/$f" 2>&1 done let index++ done <file.csv >a.txt
keeping array of directories examine each iteration isn't particularly elegant; perhaps massage input data or problem statement internally consistent.
arrays bash feature, not work sh
(but supported in similar form in ksh
, zsh
well, believe).
this more elegant if didn't use comma-separated input. shell excellent @ parsing space-separated tokens. muck ifs=,
achieve same effect comma-separated list of values drive for
loop.
Comments
Post a Comment