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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cat certain files in directories to files named after the dir?
# 1  
Old 12-14-2009
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 Capitella_sp part represents the name of the species and varies from file to file.

I'm trying to write a script that will go through each subdirectory and concatenate the contents of all the _prot_hits.fasta files into one file in the main directory named like KOG0001.fasta, KOG0002.fasta, and so on. I think I have it figured out except how to reference the source files that I want. Can anyone help me out?

Code:
find . -maxdepth 2 -type f -name "KOG[0-9][0-9][0-9][0-9]*_prot_hits.fasta" -printf "%p\n" | awk -F"_" '{print $1}' | sed 's/$/&.fasta/g' awk -F"/" 'BEGIN {filename=$3 while((getline line < **original_source_files** ) > 0) {print line >> filename} close(filename)}'

Thanks!
Kevin
# 2  
Old 12-15-2009
Code:
for i in KOG????;do find $i -name Capitella_sp_prot_hits.fasta -exec cat {} >> $i.fasta \; ;done



---------- Post updated at 11:46 PM ---------- Previous update was at 11:44 PM ----------

Shorth on bash
# 3  
Old 12-15-2009
Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

3. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

4. Shell Programming and Scripting

.sh script / Check for file in two directories then cat the files

Hi, Here is what i'm trying to do, -Check in two directories for a user inputed filename -Then cat all the version found of the file to the current screen I am a total nembie to programming, here what i have done so far.... #!/bin/bash #Check in /home/loonatic and /var/named/master... (2 Replies)
Discussion started by: Loonatic
2 Replies

5. Shell Programming and Scripting

How to get a list of files in a dir w/o sub-directories?

Hi I am looking for the correct syntax to find all files in the current directory without listing sub-directoris. I was using the following command, but it still returns subdirectoris and files inside them: $ ls -laR | grep -v ^./ Any idea? Thanks PS I am in ksh88 (4 Replies)
Discussion started by: aoussenko
4 Replies

6. Shell Programming and Scripting

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (4 Replies)
Discussion started by: Sriranga
4 Replies

7. UNIX for Dummies Questions & Answers

want to move files in a dir into different directories based on the filename

I want to move the files in a dir to different dirs based on their file names. Ex: i have 4 different files with name - CTS_NONE_10476031_MRL_PFT20081215a.txt CTS_NONE_10633009_MRL_PFT20091020a.txt CTS_NONE_10345673_MRL_PFT20081215a.txt CTS_NONE_10872456_MRL_PFT20091020a.txt and the 1st... (2 Replies)
Discussion started by: Sriranga
2 Replies

8. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

9. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies

10. Shell Programming and Scripting

cat files in different directories

i have data files in different directories like /jadat /cadat etcc... i have list of this directories in a file files. content of files: ja ca directories: /jadat /cadat file in each of these directories natt_trans_like.dat i need to loop though each directory for a... (1 Reply)
Discussion started by: dsravan
1 Replies
Login or Register to Ask a Question