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
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,
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.
Summary: You can't have two files with the same name. The OS won't allow that. Apparently there are hidden characters in one of the file names. That also happens when the OS seems to not find a file. To you ...
Summary: What's wrong with: *.<suffix> For example, if you have files with the name: junk.txt junk1.txt junk.doc junk1.doc You'd type rm *.txt to get rid of the .txt files. ...
Summary: Hi all I concatenate files using cat. Each file contains only one csv data. for example, file1 100 file2 200 cat file1 file2 > newfile newfile 100 200 However, is there any way to insert identifier w...