Avatar of Barry62
Barry62Flag for United States of America

asked on 

Searcg for text string in unix files

I have a task that I have no idea how to do.  I am supposed to search through dozens of directories on our Unix system and find every occurrence of a string in the files.  I need to list the location and name of the files as well.

Any help?
Unix OS

Avatar of undefined
Last Comment
Barry62
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Hi,

basically it's

grep -R "string" directory

If you need only filenames, not matching lines it's

grep -lR "string" directory

Please note that the above commands search the subdirectories of "directory" as well, so if the directories you have to search in are all under the same top level directory you'll have to issue the command only once against that top level directory.
Avatar of Barry62
Barry62
Flag of United States of America image

ASKER

-R is apparently an illegal option
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Barry62
Barry62
Flag of United States of America image

ASKER

Yes, it is HPUX.  I will try again Monday morning
Avatar of Barry62
Barry62
Flag of United States of America image

ASKER

That worked.  Thanks!  

I added an i to the l option because I needed a non-case sensitive script.  But that got me what I needed.
Unix OS
Unix OS

Unix is a multitasking, multi-user computer operating system originally developed in 1969 at Bell Labs. Today, it is a modern OS with many commercial flavors and licensees, including FreeBSD, Hewlett-Packard’s UX, IBM AIX and Apple Mac OS-X. Apart from its command-line interface, most UNIX variations support the standardized X Window System for GUIs, with the exception of the Mac OS, which uses a proprietary system.

33K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo