LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-21-2015, 02:33 PM   #31
atjurhs
Member
 
Registered: Aug 2012
Posts: 311

Original Poster
Rep: Reputation: Disabled

so i kinda cheated, i have an awk script that turns a header row into 1 column with the fields as rows, and i ran that on each file in the dir, the painful brute squad, i probably could have put it in a do loop, oh well

then i ran

Code:
 find . -type f -name '*.txt' | xargs grep -i -o -n "what_im_looking_for" > outfile.out
the out file wasn't cinderella pretty but nice enough, when i get a new set of files and a new dir, ut'oh, i'll have to run the brute squad again

tabby
 
Old 10-24-2015, 09:45 AM   #32
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Code:
for f in *.txt; do head -10 $f > /directory/$f; done
grep -n -b -m 1 -w ".*im_looking.*" /directory/*.txt > oufile.out
The first line is a for ; do ; done loop.
The f in *.txt creates a list of filenames ending with .txt in the current directory and each filename is assigned in turn to the variable f on each pass through the loop. The head -10 $f reads the first ten lines in the file with the filename in the variable f. The > /directory/$f sends (redirects) the lines that were read to a file with the same name in another directory. You need to supply an appropriate directory name.
The second line searches for whole words containing the string im_looking in the newly created files. The > oufile.out sends (redirects) the results of the search to the file outfile.out in the current directory.

Last edited by allend; 10-24-2015 at 09:52 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] grep: find files that do not have multiple different strings kmkocot Linux - Newbie 4 04-22-2015 12:55 PM
Searching for multiple patterns with grep dznunn Programming 2 06-26-2012 09:52 AM
Problem Searching for php files with Find and Grep ssmela Linux - General 3 11-02-2010 01:55 PM
searching within files. cat grep find w3bd3vil Linux - Newbie 4 10-13-2008 03:59 AM
Searching in files: How do I grep better? Elomis Linux - General 5 12-19-2007 01:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration