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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Find all files containing string not following symlinks CAT (modified) output content to /filename
# 1  
Old 03-26-2016
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 work. But the output filenames come in one string and I can't figure out how to CAT them one by one into regexed files one by one collocting them in one target dir.

xargs -r0 --arg-file | (find . -type f -exec grep -lZi string {} + )
# 2  
Old 03-26-2016
Does your grep have the -r or -d recurse option?

cat doesn't offer any data manipulation opportunities, nor does it understand regexes. So you may want to look into e.g. awk to perform that task. With that, you can do without grep at all.
What is the contents of your null-terminated "arg-file"? What do you need the xargs for at all? find doesn't read stdin.

Last edited by RudiC; 03-26-2016 at 09:41 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cat files listed in text file and redirect to new directory with same filename

I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Discussion started by: trigger467
5 Replies

2. Shell Programming and Scripting

Find file by filename or with newest modified date

Hi, I have a directory that has numerous files in it, and there is two which are named "filerec_ddmmyyHH24MMSS" by the time they are created so "filerec_010615012250" was created at 01:22:50 on 1st June 2015. I need to find the most recently created of those 2 files and get the contents of... (4 Replies)
Discussion started by: finn
4 Replies

3. Shell Programming and Scripting

Recursively cat files in a directory with filename printed first.

I want to recursively cat the content of files in a directory e.g. find /etc -type f -exec cat {} \; But I want it to print the file name first and then the content. For example let's say /etc/statetab and /etc/colord.conf will be printed first then I want the output to look something like; ... (6 Replies)
Discussion started by: lewk
6 Replies

4. UNIX for Dummies Questions & Answers

cat files from subdirectories output using same filename

Hi, I need to concatenate data files with a .mp extension that are stored in directories by year. I want to keep the same filename as an output for example: for the file name p030.mp, which resides in the following subdirectories: /2000/p030.mp /2001/p030.mp /2002/p030.mp I want to:... (4 Replies)
Discussion started by: cmshreve
4 Replies

5. Shell Programming and Scripting

Search for string in filename, not file content

How can I search for a string in a filename? For example, I want to know if a filename (not the file contents) contains the string "test". (3 Replies)
Discussion started by: daflore
3 Replies

6. Shell Programming and Scripting

cat and output filename

Hi, how I can display a file with cat and printing the filename before each line. e.g. file1 { one two three four five } Output: file1:one file2:two file1:three file1:four file1:five (12 Replies)
Discussion started by: Timmää
12 Replies

7. Shell Programming and Scripting

How to get a filename modified by attaching modified timestamp

Hi, I want to modify a filename in AIX by attaching the last modified timestamp. I want the timestamp completely in numerical format (eg:200905081210. yr-2009, mnth - 05, date -08, hr - 12, mins - 10). For example if the filename is a.log and it was modified on April 6th 2008 at 21.00. I... (16 Replies)
Discussion started by: Ruks
16 Replies

8. Shell Programming and Scripting

find and replace in subdirectory (filename & content - both)

Hi, I have to rename all occurance of CUST_MST to RESELLER_MST both in filename and file content under a directory (say D0) which contains multiple (2-3 levels) sub directory. Example: D0 -> D1 -> D2 has a file CUST_MST_TEMP.txt this contains : > cat /D0/D1/D2/CUST_MST_TEMP.txt... (3 Replies)
Discussion started by: sabyasm
3 Replies

9. UNIX for Advanced & Expert Users

Find and store files based on FileName and Modified Time

Hi, I am currently using the following command: files=(ls enuCPU??.????.exp ntuCPU??.????.exp) I need to now change the commmand to store the file names of files that have been modified before datetime equal to say '02/16/2008 20:30:00' What could I use? (2 Replies)
Discussion started by: edisonantus
2 Replies

10. UNIX for Dummies Questions & Answers

find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who... (4 Replies)
Discussion started by: kollerj
4 Replies
Login or Register to Ask a Question