- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell script
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
Forums
Discussions
Discussions
Discussions
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
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
10-23-2002 11:08 PM
10-23-2002 11:08 PM
I need a shell script which look in a directory and printout to a file only the names of the files that contain a specified string (for example "record 19").
Any idea?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 11:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 11:19 PM
10-23-2002 11:19 PM
Re: shell script
you could try this:
# find
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 11:23 PM
10-23-2002 11:23 PM
Re: shell script
find
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 11:33 PM
10-23-2002 11:33 PM
Re: shell script
John: the output file was empty!
Christian: some output but not only filenames, also content!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2002 11:38 PM
10-23-2002 11:38 PM
Re: shell script
I think that any solution with find should also work and display only filenames if you use the '-l' grep option. The only problem is that it will always try to explore also any subdirectories, not only the starting points. The '-type f' limit only the grep, but not the subdirectory searches.
Regards,
Jean-Louis.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2002 12:19 AM
10-24-2002 12:19 AM
Re: shell script
# find . -path "./*" -prune|xargs grep "record 19" |awk -F: '{print $1}'
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2002 01:17 AM
10-24-2002 01:17 AM
Re: shell script
grep -l "$STRING" $DIR/* > outputfile.out
Chuck J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2002 02:18 AM
10-24-2002 02:18 AM
Re: shell script
File names:
# find dir | grep -i pattern
File content, use GNU grep:
# grep -l -r pattern dir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2002 02:36 AM
10-24-2002 02:36 AM
Re: shell script
I meant the files that contain a specific string,
not the names of the files that contain a specific string :-))
Anyway, thanx for your care!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2002 05:26 PM
10-24-2002 05:26 PM
Re: shell script
find . -name "*" |xargs grep "ksh" |awk -F: '{print $1}'
which cancel off the -prune, will enable the command to search further down the directory. This might be useful sometimes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2002 11:16 PM
10-24-2002 11:16 PM
Re: shell script
In fact I don't need a shell script to do that. But it was a good example that in Unix there are more solutions for one problem.