unix - concatenate files with similar names using shell -
i have limited knowledge of shell scripting, example if have following files in folder
abcd_1_1.txt abcd_1_2.txt def_2_1.txt def_2_2.txt
i want output abcd_1.txt, def_2.txt
. each pattern in file names, concantenate files , generate 'pattern'.txt output
patterns list <-? in patterns; echo cat "$i"* > "$i".txt; done
i not sure how code in shell script, appreciated.
maybe (assumes bash, , didn't test it).
declare -a prefix files=(*.txt) f in "${files[@]"; prefix[${f%_*}]= done key in "${!prefix[@]}"; echo "${prefix[$key]}.txt" done
Comments
Post a Comment