Using cat to combine files using wildcards


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using cat to combine files using wildcards
# 1  
Old 04-03-2008
Using cat to combine files using wildcards

How do I use cat (presumably with a sh script) to combine all the files in a directory without listing them individually.

Thank you for your patience with this very elementary question.Smilie
# 2  
Old 04-03-2008
try this:
Code:
for file in *; do cat $file >> newfile; done

# 3  
Old 04-03-2008
Or simply (if no subdir present):
Code:
cat dirname/* >newfile

This User Gave Thanks to Klashxx For This Post:
# 4  
Old 04-03-2008
A complicating feature

Thank you for your replies!

Unfortunately, here is a partial list of my file names:

1 INSERM Avenir, Epidemiology of Sudden Death in the Population, Paris XI University.rtf

24% mortality in the ICD group, 55% in the pharmacological therapy group, and 48% in the group receiving no therapy.rtf

A frequently observed and notable aspect of SCD is its unpredictable and seemingly random nature of onset. Accordingly, one of.rtf

A multicenter experience with novel subcutaneous patch.rtf

A subcutaneous ICD system is a very useful new treatment approach. This technique is especially suitable for young children and.rtf


As you can see, they contain spaces, punctuation marks, and pretty much every other forbidden thing Unix can imagine.

What happens when I do "cat dirname/* > newfile" is that I just get the first file.

When I try the script: "for file in *; do cat $file >> newfile; done", it does not like the file names.

Sorry for the horrible complication...
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Shell Programming and Scripting

Combine files

I have n of files with ending with _ZERO.txt need to combine all file ending with _ZERO.txt into 1 file ex: A_ZERO.txt 1 2 B_ZERO.txt 3 4 Output: FINAL.txt 1 2 (3 Replies)
Discussion started by: satish1222
3 Replies

3. Shell Programming and Scripting

combine two files...

Hi, i have two files. i want to combine records from these two files in below manner :- first line from first file(1st line) 2nd line from 2nd file(1st line) 3rd line from 1st file(2nd line) 4th line from 2nd file(2nd line) so on.... (1 Reply)
Discussion started by: deepakiniimt
1 Replies

4. UNIX for Dummies Questions & Answers

copying files with wildcards

Hello, I am attempting to copy a series of files using a wildcard into a new subdirectory. however, I am clearly doing something wrong as it is not working. I want to copy all files in the directory that start with the letters kl but have other letters after this initial two letters into another... (7 Replies)
Discussion started by: goldenone
7 Replies

5. Shell Programming and Scripting

combine multiple files by column into one files already sorted!

I have multiple files; each file contains a certain data in a column view simply i want to combine all those files into one file in columns example file1: a b c d file 2: 1 2 3 4 file 3: G (4 Replies)
Discussion started by: ahmedamro
4 Replies

6. Shell Programming and Scripting

Perl, open multiple files with wildcards

I have a question regarding Perl scripting. If I want to say open files that all look like this and assign them to a filehandle and then assign the filehandle to a variable, how do I do this? The file names are strand1.fa.gz.tmp strand2.fa.gz.tmp strand3.fa.gz.tmp strand4.fa.gz.tmp ...... (6 Replies)
Discussion started by: japaneseguitars
6 Replies

7. Shell Programming and Scripting

cat certain files in directories to files named after the dir?

Hi all, I have a directory with many subdirectories each named like so: KOG0001, KOG0002, ...KOG9999. Each of these subdirectories contain a variable number two kinds of files (nuc and prot) named like so: Capitella_sp_nuc_hits.fasta (nuc) and Capitella_sp_prot_hits.fasta (prot). The... (2 Replies)
Discussion started by: kmkocot
2 Replies

8. Shell Programming and Scripting

rename multiple files with wildcards

Hi All I am having hundred over file in the below pattern. AA050101.INI BB090101.INI . . ZX980101.INI Need to rename these files with an extension .bak AA050101.INI.bak BB090101.INI.bak . . ZX980101.INI.bak (5 Replies)
Discussion started by: karthikn7974
5 Replies

9. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

10. UNIX for Dummies Questions & Answers

Move files using wildcards ???

Hi all, Would like to rename all files using wildcards - if at all possible! As an example I have the following files: Nov01_df Nov02_df Nov03_df ...... Nov28_df Nov29_df Nov30_df I'd like to have these renamed as "df??" where ?? is the number from the original file name. Any... (5 Replies)
Discussion started by: Cameron
5 Replies
Login or Register to Ask a Question