I have a requirement of shell script where i need to read the File name i.e ls -t | head -1 and Match that Filename with some delimited values which are in a separate File.
For Example i am reading the File name i.e (ls -t | head -1) after that i need to read one more sequential file which contains some delimited values like this
So If my file name matches kkkk then i need to match with the above list and i need to get /ddd/eee/kkkk/fff if my file name is nnnn then i need to get /jjj/kkk/lll/nnnn .
$
$ # For simplicity, assume that the files to loop through are the ones that have 4 characters
$
$ ls -1 ????
aaaa
kkkk
nnnn
xxxx
$
$
$ # Assume that the sequential file is list.txt
$
$ cat list.txt
00000%/aaa/bbb/ccc%kkkk%/ddd/eee/kkkk/fff^%^12345%/ggg/hhh/iii%nnnn%/jjj/kkk/lll/nnnn^%^
$
$
$ # something like this could be done
$
$ for i in ???? ; do echo "File = $i"; sed 's/\^%\^/\n/g' list.txt | grep "%$i%" | sed 's/^.*%//'; done
File = aaaa
File = kkkk
/ddd/eee/kkkk/fff
File = nnnn
/jjj/kkk/lll/nnnn
File = xxxx
$
$