简体   繁体   中英

Bash script to Comparing list of variable filenames from one txt file to another and do something in linux

My aim is to read the filenames in temp11 file one by one and compare it with the filenames in the tj_mail.txt

if it matches, do nothing , if it doesn't, move the file from the from destination to another.

temp 11 has abc.xlsx and tj_mail.txt has /path1/path2/abc.xlsx

so as they are not matching, it is supposed to perform the Move operation

cat /mae/SrcFiles/Target_Shellscript_Autodownload/Airtime_Activation/temp11 | while IFS="" read -r -d $'\0' file;
do
    read "${file?}"
    if grep -qF "$$file" /mae/scripts/tj_mail.txt;then
    :
    else
        mv $file /marketsource/SrcFiles/Target_Shellscript_Autodownload/Airtime_Activation/newthings
    fi
done

There are no error, but doing nothing too, it seems to be not reading the file

There's no need to use read and grep . Use comm to compare the two files and get the files that are missing, and pass those to mv .

comm -23 <(sort /mae/SrcFiles/Target_Shellscript_Autodownload/Airtime_Activation/temp11) <(sort /mae/scripts/tj_mail.txt) | 
    xargs mv -t /marketsource/SrcFiles/Target_Shellscript_Autodownload/Airtime_Activation/newthings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM