Visit Our UNIX and Linux User Community


how to cat files with path? Help plz


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers how to cat files with path? Help plz
# 1  
Old 01-08-2008
how to cat files with path? Help plz

Hi,
I am trying to organize my data files and I would like to know how to cat files with path. Note that the correct command may not be "cat" though.
For example, I have:
abc/data/1/title
dca/data/2/title
gpd/data/1/title
....

I'd like to have a file listing the title info from different directories, as well as directory paths.

Thanks

Simon
# 2  
Old 01-08-2008
Question

How should the o/p look like Smilie
# 3  
Old 01-08-2008
Quote:
Originally Posted by shamrock
How should the o/p look like Smilie

The output should be like:
48/pdata/1/title:ub2k63r, 1mM in PBS buffer, crp, for nemo titration
49/pdata/1/title:ub2k63r nemo titration, 1/5 nemo
50/pdata/1/title:ub2k63r nemo titration, 1/5 nemo
83/pdata/1/title:quick T2_2 of n15-NEMO+k63-Ub2

The text after colon(Smilie is the text written in the title file.
Actually I succeeded once before, but I forgot what command(s) I used. I think I used "find", but can't make it work this time.

Thanks,
# 4  
Old 01-08-2008
Java

Code:
for file in `find /base/path -type f -name "title"` ; do echo "${file}:`head -1 $file`"; done

# 5  
Old 01-08-2008
Quote:
Originally Posted by Smiling Dragon
Code:
for file in `find /base/path -type f -name "title"` ; do echo "${file}:`head -1 $file`"; done

Hi, Thanks for the suggestion.
However, I am still confused. Could you be more detailed?
Thanks
# 6  
Old 01-08-2008
Quote:
Originally Posted by zdn3023
Hi, Thanks for the suggestion.
However, I am still confused. Could you be more detailed?
Thanks
Not sure what you mean... Does the code not work? What error do you get?
# 7  
Old 01-08-2008
I think you want to cat the files, but you want the filename printed for each cat (the files contain but a single line each?). AFAIK cat will not do this, but other commands will:

Code:
# Prints filename in front of each line of all files in current dir
 grep . *

# Does the same as above, but finding all files named "title"
 find . -name "title" -type f -exec grep . {} /dev/null \;

Why the "/dev/null" you ask? Because grep will only print the filename if there is more than one file listed, so I use /dev/null as a second file.

The dot (".") RegEx matches all nonblank lines.
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #362
Difficulty: Medium
The sed command first appears in Version 5 AT&T UNIX.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving files from parent path to multiple child path using bash in efficient way

Hi All, Can you please provide some pointers to move files from Base path to multiple paths in efficient way.Folder Structure is already created. /Path/AdminUser/User1/1111/Reports/aaa.txt to /Path/User1/1111/Reports/aaa.txt /Path/AdminUser/User1/2222/Reports/bbb.txt to... (6 Replies)
Discussion started by: karthikgv417
6 Replies

2. Shell Programming and Scripting

CAT 3 files with the same name in 3 different folders

I am trying to cat 3 files. They all have the same name MFExtract.txt. But, they are in 3 seperate file names. Any idea how I could cat the 3 together. It's throwing me off figuring out a way because the names are the same. I was thinking just doing a 3 cat commands with the full path names and... (2 Replies)
Discussion started by: risarose87
2 Replies

3. Shell Programming and Scripting

Cat files situation

Hello, I am PhD student (Biomedical sciences) and very new to Linux. I need some help with the following task : I have files in the following format for their names : An_A1_nnn_R1.txt; An_A1_nnm_R1.txt; An_A1_nnoo_R1.txt An_A2_nnn_R1.txt; An_A2_nnm_R1.txt; An_A2_nno_R1.txt ... (8 Replies)
Discussion started by: Julio Finalet
8 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. 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

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

7. Shell Programming and Scripting

shell script to call other files..plz help

Hi all, I have a number of shell script,perl script.. etc in a directory,which i need to execute in some order.Now i need to create a script to call all these files in that order..so that the new script will execute all the files one by one....plz help this is urgent. Thanks In advance Anju (3 Replies)
Discussion started by: anju
3 Replies

8. Shell Programming and Scripting

Shell script to find out 2 last modified files in a folder..PLZ HELP!!!!!!!!!

hi all, I need to find out the last 2 modified files in a folder.There is some way by which,we can check the timestamp and find out..??please help this is urgent. Thanks in Advance Anju (3 Replies)
Discussion started by: anju
3 Replies

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

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies

Featured Tech Videos