Sample Header Ad - 728x90

filewatcher script in ksh script

0 votes
0 answers
166 views
I wanted to edit a already created filewatcher script with the given logic the source file path is stage path (stage/filewatcherwrap.ksh) there are 4 files in the below given format in stage path 1. abc_xyz_07062022_120648.txt 2. abc_efg_07062022_120648.txt 3. abc_xyz_PQR_07062022_120648.txt 4. abc_efg_PQR_07062022_120648.txt Lets assume :- files 1 and 2 belongs to A files 2 and 3 belongs to B I wanted to write these files to a filewatcher.txt file placed in ../temp path while writing these files, I give the file naming as below, 1. abc_xyz_*.txt 2. abc_efg_*.txt 3. abc_xyz_PQR_*.txt 4. abc_efg_PQR_*.txt here, the * takes the timestamp value while writing to the temp/filewatcher.txt script I wanted to write these 4 files by taking the considering pattern matching technique given below if there are 2 underscores, it should write both the A files -->abc_xyz_07062022_120648.txt -->abc_efg_07062022_120648.txt if there are 3 underscores, it should write both the B files -->abc_xyz_PQR_07062022_120648.txt -->abc_efg_PQR_07062022_120648.txt Can this be done using nested for loop..? if returns 2 then it should write first 2 files to the temp/filewatcher.txt file if returns 3 then it should write last 2 files to the temp/filewatcher.txt file NOTE :- while giving abc_xyz_*.txt (it should not consider abc_xyz_PQR_*.txt file) to check the number of underscores, I have used the below logic in putty ls abc_xyz_*.txt|cut -d "." -f1|rev|cut -d "_" -f3-|awk -F "_" '{print NF}' please help! Thanks in advance..
Asked by Jayashree (1 rep)
Jul 6, 2022, 06:58 AM