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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -