Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to concatenate multiple files in a script into a single file?

Status
Not open for further replies.

RajShekar

Programmer
May 27, 2004
14
0
0
US
I would like to have a script that concatenates multiple files in a folder into a single file.Any help is appreciated. Thanks.

Something like this.....
for PROC_DATE in `find path -name '*'|sort -u`
do
concatenate logic
....
....
done
 
If no subdir search needed:
cat /path/to/dir/* > /path/to/output
If subdir recursion needed:
find /path/to/dir -type f | sort | xargs cat > /path/to/output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
find path -type f |sort -u | xargs cat > /path2new/concatenated.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
All the files that I want are in the same directory, but the problem is I donot want to cat all the files in that directory.....Please let me know how to go about that...
 
let me know how to go about that...
To go about WHAT ?
You posted that:
for PROC_DATE in `find path -name '*'
clearly you wanted ALL files ?
What are the new rules and what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
[quite]
All the files that I want are in the same directory, but the problem is I donot want to cat all the files in that directory
[/quote]

hm...... sounds like a contradiction....

care to clear things up?

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Sorry....I donot want all the files just the files that I will get with the FOR statement, Thank You. :)
 
The for statement is

for PROC_DATE in `find /prod/home01/store/csa/data/data01/input/amerifee/ -name '[0-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9]'|so
rt -u`
 
for PROC_DATE in `find path -name '*'|sort -u`
you'll get ALL files, directories, namedpipes, .... in the path directory and all the subdirectories.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top