Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have thousands of .txt files in directory. Their names are:

ch14.ta_20452_206652_15-84.txt
ch14.ta_20452_206652_786-14.txt
ch14.ta_20452_206652_77-85.txt
ch14.ta_20452_206652_81-78.txt
ch2.ta_16903_17204-41-44.txt
ch2.ta_16903_17204-2-46.txt
ch2.ta_16903_17204-61-47.txt
ch2.ta_16903_17204-73-52.txt

I want to merge files with the similar beginning of the name (exp: ch14.ta_20452_206652 or ch2.ta_16903_17204) into one txt.

Tried to do it manually with:

cat *ch14.ta_20452_206652* > ch14.ta_20452_206652.txt

But it's impossible and driving me crazy. Hope that someone could help me

share|improve this question
    
sorry. mistake. and seems I can't delete this comment. :( –  rush Mar 22 '12 at 10:14
add comment

1 Answer

Hope that helps:

for i in ch* ; do cat $i >> $(echo $i | sed 's/\(ch[0-9]*\.ta_[0-9]*_[0-9]*\).*/\1.txt/') ; done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.