Using cat on specific files only


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using cat on specific files only
# 1  
Old 03-22-2012
Using cat on specific files only

I am concatenating txt-files using cat:
Code:
cat *.txt > file.dat

However, the same directory has the installation instructions included, which is also a txt file: install.txt
I currently have the install.txt file renamed to install._txt, but I prefer a solution using regular expressions.
Is there an elegant way to exclude the install.txt from being concatenated as well?
# 2  
Old 03-22-2012
Hi figaro,

One way:
Code:
$ awk '{ if ( FILENAME == "install.txt" ) { nextfile } ; print }' *.txt >file.dat

# 3  
Old 03-22-2012
In bash pattern matching try
Code:
shopt -s extglob
ls !(install|another|someother).txt

files with .txt will list excluding the ones in the alternation pattern !(pattarn1|pattern2)

If you have lots of exclusions, this won't be "elegant".

ksh93 does similar pattern matching, but of course it is different, check your documentation.
# 4  
Old 03-27-2012
Thank you for your answer. I have tried several combinations of the exclamation mark solution (!), but getting "Badly placed ()'s" error. The current shell is csh, so that may have something to do with it.
# 5  
Old 03-27-2012
For slower action you can also use find with cat.
Code:
find . -type f -name "*.txt" ! -name "install.txt" -exec cat > outfile.txt {} \;

Hope that helps
Regards
Peasant
# 6  
Old 03-29-2012
Works great, thanks.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cat N files in a folder

I am new to Linux and I am trying to cat only N files in a folder. N is dynamically given number at runtime. If I give N as 2 then cat only 2 files in the folder and If I give N as 5 then cat only 5 files in the folder. Is there any way to do that? (6 Replies)
Discussion started by: KMusunuru
6 Replies

2. UNIX for Dummies Questions & Answers

Highlighting specific column in cat/grep

I have a large * delimited text file and need to highlight specific columns on specific lines. The file looks similar to this: ABC*01*00*01*00000 000000 *00000 000000 *35*0*0*0*0*20000*0*0*1*0000*00*4*0*3*0*0*1*0* *35*0000*001*4*1OT2*0148*0*0*0*0*0*0*6A7801B0**TEST1... (1 Reply)
Discussion started by: say170
1 Replies

3. Shell Programming and Scripting

grep and cat based on specific mod date

I'm trying to figure out how to open and copy all contents of files last modded on aug 14 to one single text file. Also, I'm trying to do this in one command string. I have ls -l -R | grep "Aug 1" but all this does is print the -l info with Aug 1 in it. how can I modify this so that ls... (3 Replies)
Discussion started by: mmixology
3 Replies

4. 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

5. Shell Programming and Scripting

Copying specific files from remote m/c to specific folders

Hi All, I am trying to rsync some of the latest files from remote m/c to my local linux box. Folder structure in my remote m/c looks like this /pub/Nightly/Package/ROLL/WIN /pub/Nightly/Package/SOLL/sol /pub/Nightly/Package/SOLL/linux Each of the folder contains gzip files which on daily... (0 Replies)
Discussion started by: jhoomsharabi
0 Replies

6. 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

7. UNIX for Dummies Questions & Answers

cat files

Hi, I was a typical Windows guy. Like to do things just by clicking my mouse:cool:. I got a new job now...where they are big on unix. I am trying to wet my fingures now with unix. Haven't taken the dive yet. I am trying to find a solution for this problem. Please help me with some... (4 Replies)
Discussion started by: sandeep78
4 Replies

8. Shell Programming and Scripting

cat /proc/ files

Hi, I need to write a shell script that should lists only the files that starts with alphabet from the /proc dir and then I have to cat those files and redirect to a file. But my below script is not working. It is reading the first file properly but not the subsequent files. Please throw a... (2 Replies)
Discussion started by: royalibrahim
2 Replies

9. UNIX for Dummies Questions & Answers

grep/cat/more -- search in a txt file and display content from a specific "keyword"

Hi, I have a .txt file Sample: ===================== NEXT HOST ===================== AEADBAS001 ip access-list extended BLA_Incoming_Filter ip access-list extended BLA_Outgoing_Filter access-list 1 permit xxxxxxxxxxxxxx access-list 2 permit xxxxxxxxxxxxxx =====================... (4 Replies)
Discussion started by: I-1
4 Replies

10. Shell Programming and Scripting

KSH CAT Two files into one

Quick question, File A has one line (10 charachters), File B has one line (10 charachters). how do a concat these two files together to produce a file (File C) that has the contents of Files A + B together onto one line of 20 Charachters if I use: cat FileA FileB > FileC I get the... (5 Replies)
Discussion started by: kshelluser
5 Replies
Login or Register to Ask a Question