Computing.Net > Forums > Unix > Concatenate Files with similar name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Concatenate Files with similar name

Reply to Message Icon

Name: badhri
Date: January 29, 2004 at 16:05:52 Pacific
OS: Saun Solaris
CPU/Ram: 8
Comment:

Greeting.

I need to concatenate all the files with similar File names. For Example, I have 5 files,

1_100
2_100
3_200
4_200
5_300

Now I need to have 3 files by names,

100 : cat (1_100, 2_100)
200 : cat (3_200, 4_200)
300 : cat (5_300)

Thanks,
Badhri ...




Sponsored Link
Ads by Google

Response Number 1
Name: thepubba
Date: January 29, 2004 at 17:00:29 Pacific
Reply:

This script will create files named 100, 200 and 300. I put the 400 in there to demonstrate how to handle no files. This script will work with the examples you provided.

#!/bin/ksh
for name in 100 200 300 400
do
files=$(ls *$name 2> /dev/null)
if [[ -z $files ]]
then
print "No files"
else
for file in $files
do
cat $file >> $name
done
fi
sleep 1
done

Jerry


0

Response Number 2
Name: badhri
Date: January 29, 2004 at 17:10:09 Pacific
Reply:

Hi Jerry,

I cannot hardcode these numbers (100,200,300). I need to dynamically determine this and then do the rest.

Badhri ...



0

Response Number 3
Name: thepubba
Date: February 1, 2004 at 22:21:51 Pacific
Reply:

When you say dynamically determine them, do you mean by reading the input file? If so, it is fairly easy to read the last portion of the input line by using a typeset in the Korn shell. Let me know and I can modify the script.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Concatenate Files with similar name

Files with equal names www.computing.net/answers/unix/files-with-equal-names/4198.html

rm files with same prefix, diff suf www.computing.net/answers/unix/rm-files-with-same-prefix-diff-suf/5644.html

concatenate files with identifier www.computing.net/answers/unix/concatenate-files-with-identifier/8249.html