- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Finding a string in a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 05:30 AM
тАО04-09-2003 05:30 AM
Finding a string in a file
How i can find a string in a file?
Sorry, but i'm a "freshman" in HPUX-11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 05:42 AM
тАО04-09-2003 05:42 AM
Re: Finding a string in a file
# grep thestring filename
For example, if you want to find the string "host" in the file '/etc/hosts' you would do:
# grep hosts /etc/hosts
See the man pages for 'grep'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 05:42 AM
тАО04-09-2003 05:42 AM
Re: Finding a string in a file
RGds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 05:43 AM
тАО04-09-2003 05:43 AM
Re: Finding a string in a file
One way to find a string in a file is with the 'grep' command:
grep somestring filename
Do a 'man grep' and take a look at the docs. There are lots of regular expressions you can use for finding strings.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 05:45 AM
тАО04-09-2003 05:45 AM
Re: Finding a string in a file
two possibilities:
grep -i 'string' *
gives you the filename and the line with the string.
If you edit a file with vi:
/string 'enter'
get the curser to the string.
More questions?
Volkmar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 05:49 AM
тАО04-09-2003 05:49 AM
Re: Finding a string in a file
If you're at a prompt -
grep "string" /path/to/filename
If in "vi" -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 05:54 AM
тАО04-09-2003 05:54 AM
Re: Finding a string in a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 06:03 AM
тАО04-09-2003 06:03 AM
Re: Finding a string in a file
thanks to all of you!!
Every day, i learn more...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 06:08 AM
тАО04-09-2003 06:08 AM
Re: Finding a string in a file
grep is the tool you need to study.
grep -v something *
will print all the lines in all the files in the present directory, EXCEPT the lines that contain "something" - cool right?
grep -E "name && lastname" filename
will get name and lastname out of a file.
grep -E "name || lastname" filename
will get either name or lastname out of the file.
enough from the peanut galary -
hack away - peace
Donny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-09-2003 06:17 AM
тАО04-09-2003 06:17 AM
Re: Finding a string in a file
Want to find a text string in a file, but do not know which file or where to look?
cd to root - cd /
and type:
find . -type f -exec grep -l '
Has been invaluable for me at times.
Note: Can be a resource hog and take a long time if you have a substantial filesystem.
Enjoy HP-UX!
Kel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-10-2003 07:46 AM
тАО04-10-2003 07:46 AM
Re: Finding a string in a file
This is useful when looking for error messages, or other messages, when you don't have source code.
Again, this usually gets piped through grep...
strings
By the way, none of these answers is specific to hp-ux, they'll work with any unix/linux system.
Enjoy!