FIND and CAT troubles


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers FIND and CAT troubles
# 1  
Old 04-19-2008
FIND and CAT troubles

Hi all,

I need a big help in a problem. I have a lot of files with the name "title" on a lot of folders. Each files have one single line and I need to copy all these lines to a new file, named "all_titles". For exemple, if I have
Code:
folder1
 title
  content1

folder2
 title
  content2

I want
Code:
all_title
 content1
 content2

in differents lines. One year ago I did this using the following:
Code:
find . -name title -exec cat > all_title {} \;

Before I had a SGI IRIX, and works fine, but now I have a WindowsXP with CygWin and I get

all_title
content1content2

Itīs essential to me to get each one "content" in a single line on the new file "all_title".

Thank you for your help.

Daniel Uchoa.

Last edited by Yogesh Sawant; 04-21-2008 at 06:00 AM.. Reason: added code tags
# 2  
Old 04-19-2008
How exactly are the files encoded? In particular, do they have DOS or Unix line endings? I'm speculating you are actually getting the same result as previously, but you are viewing it with software which doesn't understand the Unix line endings.

On Unix, each line is terminated with a line feed. On DOS, each line is terminated with the sequence carriage return, line feed.

If you need to add carriage returns, see if you have unix2dos or a similar utility. Perhaps you would like to convert the source files once and for all, and not need it in your scripts after that.

By the by, if the files are all in a subdirectory directly under the current directory, a normal wildcard should suffice.

Code:
cat */title >all_title

Maybe you could use sed to add an empty line to each input file. This will produce one completely empty line if some of your files already have a proper line terminator.

Code:
sed 'a\' */title >all_title

# 3  
Old 04-20-2008
Thank you era, sed works fine to solve my problem.

solution:
Code:
find . -name title -exec sed 'a\' > all_title {} \;


Last edited by Yogesh Sawant; 04-21-2008 at 05:58 AM.. Reason: added code tags
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Single line backups with find or cat and xargs, etc

Hi, I'm new here and this is my first post. I used command line Unix at work for 3 years... about 10 years ago! Now I can't figure out nor hunt down examples of how to do the following: Say I built a list of file to backup like this: find ~ -name "*.pdf" -print >> MYPDF.txt So I am using find... (6 Replies)
Discussion started by: hwilliam777
6 Replies

2. UNIX for Dummies Questions & Answers

Find all files containing string not following symlinks CAT (modified) output content to /filename

This should recursively walk through all dirictories and search for a specified string in all present files, if found output manicured content (eg some regex) with CAT into a specified directory (eg /tmp/) one by one, keeping the original names This is what I have so far, which seems to... (1 Reply)
Discussion started by: lowmaster
1 Replies

3. UNIX for Dummies Questions & Answers

Find and cat top lines recursively

I have a folder structure with multiple sub directories MAIN FOLDER1 SUBFOLDER1 files...... FOLDER2 SUBFOLDER1 files...... etc and I want to find a way to create an output of every files first 20 lines. I've been searching and testing and failing. I can do it in a... (2 Replies)
Discussion started by: darbs121
2 Replies

4. UNIX for Dummies Questions & Answers

Help on cat filelist.txt |xargs -n1 find

I am trying to find all the files listed in a filelist.txt. Why cant I use something like this cat filelist.txt | xargs -n1 find $path (2 Replies)
Discussion started by: dragonpoint
2 Replies

5. Shell Programming and Scripting

find | xargs cat

Hi, I am having trouble getting a combination of commands to work. I need to traverse through all sub-directories of a certain directory and 'cat' the contents of a particular file in the sub-directories. The commands on their own work but when I combine them I get no output. The... (4 Replies)
Discussion started by: DownunderDave
4 Replies

6. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

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

8. Shell Programming and Scripting

find | xargs cat

Hai I just want to find a file *.txt in particular direcotry and display the file name puls the content. Do someone know hot to do this, thanks. I try : find test/ -name '*.txt' | xargs cat but It does'nt print out the file name, i want something below print out in my screen : test/1.txt... (4 Replies)
Discussion started by: asal_email
4 Replies

9. Programming

compiling troubles

i keep getting the following error with the code segment below when i try to compile the program. The code is from 'defs.h' parse error before '(' parse error before ')' stray '\' in program this is the code segment and the error is on the second line of the segment #define... (1 Reply)
Discussion started by: token
1 Replies
Login or Register to Ask a Question