Print only Filename based on given String on file name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print only Filename based on given String on file name
# 1  
Old 01-21-2010
CPU & Memory Print only Filename based on given String on file name

Hi, I am new to this unix world.

Any ways, I would like to write a shell script that can print the file name.

Ex :

directory will have 5 files with different name.No matter what are contents are.

Now I need to find the file which will have particular name (sub string ).Please do not look into contents.It should be in loop.
Please provide the shell script.

Please let me know if any one need more info.
# 2  
Old 01-21-2010
check the man pages of grep.
# 3  
Old 01-21-2010
Sure, I will check it.I tried find command.I found that we can search in file contents.
Can you please provide script.
# 4  
Old 01-21-2010
Code:
grep -l "ABC" /directory

# 5  
Old 01-21-2010
Will this go through in loop to look all the files.
# 6  
Old 01-21-2010
HTML Code:
grep -l "ABC" /directory
Yes no loop needed here for a single directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use while loop to read file and use ${file} for both filename input into awk and as string to print

I have files named with different prefixes. From each I want to extract the first line containing a specific string, and then print that line along with the prefix. I've tried to do this with a while loop, but instead of printing the prefix I print the first line of the file twice. Files:... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

2. Shell Programming and Scripting

Need to print the next word from the same line based on grep string condtion match.

I need to fetch particular string from log file based on grep condition match. Actual requirement is need to print the next word from the same line based on grep string condtion match. File :Java.lanag.xyz......File copied completed : abc.txt Ouput :abc.txt I have used below... (5 Replies)
Discussion started by: siva83
5 Replies

3. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

4. UNIX for Dummies Questions & Answers

Print the grepped string alongwith the filename

We have C shell and we are executing the below script: #!/bin/csh -f if ($#argv != 2) then echo "Usage $0 DirecotryPath Inputfilename" exit 1 endif set dir=$1 set fname=$2 echo $dir foreach line ( `cat $fname` ) echo \ ======================================== >>... (2 Replies)
Discussion started by: donisback
2 Replies

5. Shell Programming and Scripting

grep exact string from files and write to filename when string present in file

I am attempting to grep an exact string from a series of files within a directory and append that output to the filename when it is present in the file. I've been after this all day with no luck. Thanks for your help in advance :wall:. (4 Replies)
Discussion started by: JC_1
4 Replies

6. Linux

Find String in FileName and move the String to new File if not found

Hi all, I have a question.. Here is my requirement..I have 500 files in a path say /a/b/c I have some numbers in a file which are comma seperated...and I wanted to check if the numbers are present in the FileName in the path /a/b/c..if the number is there in the file that is fine..but if... (1 Reply)
Discussion started by: us_pokiri
1 Replies

7. Shell Programming and Scripting

awk to print lines based on string match on another line and condition

Hi folks, I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Discussion started by: rowie718
5 Replies

8. Shell Programming and Scripting

Move file based on filename

Hi All I need a script to manipulate files based on a filename: example filename: 66600_042706.pdf the script will create a directory 66000 only if this directory is not existing. If that directory is existing it will just move the file to 66000/666000_042706.pdf in addition, i want to... (4 Replies)
Discussion started by: aemestech
4 Replies

9. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

10. UNIX for Dummies Questions & Answers

find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who... (4 Replies)
Discussion started by: kollerj
4 Replies
Login or Register to Ask a Question