Search option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search option
# 1  
Old 12-09-2014
Search option

Hi,
I have to search for strings in file name something like
HTML Code:
search for "Needs" OR "History" in filename "UserStudyHistory.csv"
i know using "grep", we can search inside the file, but couldn't get commands to search in file name. please help me.
# 2  
Old 12-09-2014
Quote:
Originally Posted by JSKOBS
Hi,
I have to search for strings in file name something like
HTML Code:
search for "Needs" OR "History" in filename "UserStudyHistory.csv"
i know using "grep", we can search inside the file, but couldn't get commands to search in file name. please help me.
Hello JSKOBS,

Kindly use code tags in place of HTML tags. Following may help you in same.

Code:
awk '/Needs/ || /History/ {print}' Input_file
OR
egrep 'History|Needs' Input_file

Hope this helps.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 12-09-2014
Try out this
Code:
find . \( -name "Needs" -o -name "History" \)

---------- Post updated at 12:14 AM ---------- Previous update was at 12:11 AM ----------

More precisely you can try.
Code:
find . \( -name "*Needs*.csv" -o -name "*History*.csv" \)

This User Gave Thanks to diehard For This Post:
# 4  
Old 12-09-2014
I'm not sure I understand what you're trying to do.

If you just want to list files in the current directory with names containing "Needs" or "History", a simple starting point would be:
Code:
ls -1 *Needs* *History*

The option there is the digit one; not the letter ell.

Of if you have a grep command you like, you can turn the list of names in the current directory into a file to be processed by grep with:
Code:
ls | grep Needs

or:
Code:
ls | grep -E 'Needs|History'

or:
Code:
ls | grep -F -e Needs -e History

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 12-09-2014
Quote:
Originally Posted by diehard
Try out this
Code:
find . \( -name "Needs" -o -name "History" \)

---------- Post updated at 12:14 AM ---------- Previous update was at 12:11 AM ----------

More precisely you can try.
Code:
find . \( -name "*Needs*.csv" -o -name "*History*.csv" \)

Hello,

If I read user's requirement clearly user says to search a word/string in a file, command you have given will look for the filenames named History and Needs which is not required as per user. But if you want to look for words mentioned by user in any files then following may help us.
Code:
find -type f -exec egrep 'History|Needs' {} \;

Thanks,
R. Singh
# 6  
Old 12-09-2014
Well as per the user statement

"i know using "grep", we can search inside the file, but couldn't get commands to search in file name. please help me. "

So I think user is trying to find filename with particular string.SmilieSmilieSmilie

---------- Post updated at 12:44 AM ---------- Previous update was at 12:43 AM ----------

Quote:
Originally Posted by RavinderSingh13
Hello,

If I read user's requirement clearly user says to search a word/string in a file, command you have given will look for the filenames named History and Needs which is not required as per user. But if you want to look for words mentioned by user in any files then following may help us.
Code:
find -type f -exec egrep 'History|Needs' {} \;

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

YouTube: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search

Getting a bit more comfortable making quick YT videos in 4K, here is: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search Console https://youtu.be/I6b9T2qcqFo (0 Replies)
Discussion started by: Neo
0 Replies

2. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

3. Solaris

Unrecognized option: sparc-sun-Solaris2.10/bin/as: unrecognized option `-m32'

Hi, I installed some packages required by an app built with python. But when I try python setup.py install, I get the following error: /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/../../../../sparc-sun-solaris2.10/bin/as: unrecognized option `-m32' Could anyone tell me what's wrong... (4 Replies)
Discussion started by: Kimkun
4 Replies

4. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

5. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

6. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

7. Shell Programming and Scripting

recently introduced to the newer option for find...does an older option exist?

To find all the files in your home directory that have been edited in some way since the last tar file, use this command: find . -newer backup.tar.gz Is anyone familiar with an older solution? looking to identify files older then 15mins across several directories. thanks, manny (2 Replies)
Discussion started by: mr_manny
2 Replies

8. Post Here to Contact Site Administrators and Moderators

Idea: New search option

Hi Mods / Admins, How about a search option to allow a user to find threads that they have contributed to (e.g. "Find threads I have contributed to")? It could save time scanning pages of unrelated threads, and would allow a contributor to see the final outcome of the related threads. Just... (3 Replies)
Discussion started by: jgrogan
3 Replies

9. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

Hi all, I am parsing command line options using getopts. The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument. Below is the script: while getopts :hd:t:s:l:p:f: opt do case "$opt" in -h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies

10. UNIX for Dummies Questions & Answers

search option

how do i search for a string within a log file, if im using the tail command?? :rolleyes: (2 Replies)
Discussion started by: juststeve
2 Replies
Login or Register to Ask a Question