I am new to Unix , I need to write a script. Can someone help me with a requirement where I have list of files in a directory, I want to Merge the files if a pattern of string matches in filenames?
AAAL_555A_ORANGE1_F190404_D190408.TXT.freshfruits_20190422-115617
AAAL_555A_ORANGE2_F190404_D190408.TXT.freshfruits_20190422-115617
AAAL_555A_ORANGE3_F190404_D190408.TXT.freshfruits_20190422-115617
AAAL_555A_ORANGE4_F190404_D190408.TXT.freshfruits_20190422-115617
AAAL_555B_ORANGE5_F190404_D190408.TXT.freshfruits_20190422-115617
AAAL_555B_Orange6_F190404_D190408.TXT.freshfruits_20180422-115617
If second part of filename='555A' and third part consists of ORANGE then all Oranges/555A content files will merger into one file with filename as AAL_555a_Orange_date +"%Y%m%d".txt.
If second part of filename='555B' and third part consists of ORANGE/555B then all Oranges content files will merger into one file with filename as AAL_555b_Orange_date +"%Y%m%d".txt.
If second part of filename='555A' and third part consists of MANGO then all Mango content files will merger into one file with filename as AAL_555a_Mango_date +"%Y%m%d".txt.
Kindly help ..!
I know the below command to appended multiple files into one . But here i want to do based on patterns present in filename.
cat File1 file2 file3 >> final.txt
Something like this
for i in *.TXT; do
while field separator='_' read -r str1 num str2 ; do
if [ "$str1" = "RTG" ]; then
fi
done
done