Sponsored Content
Top Forums Shell Programming and Scripting How to grep for a string on a FILENAME? Post 302999089 by mohtashims on Tuesday 13th of June 2017 05:47:42 AM
Old 06-13-2017
Hammer & Screwdriver

Code:
if [ `echo $1 | grep -c "admin" ` -gt 0 ]

But i was looking for something simpler.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Appending to filename a string of text grep finds

I am wanting to automate a process that includes the step of appending to a filename a string of text that's contained inside the file. I.e. if filename A.fileA contains a string of text that reads 1234 after the phrase ABC, I want the shell script file to rename the file 1234_FileChecked_A.fileA.... (3 Replies)
Discussion started by: HLee1981
3 Replies

2. Shell Programming and Scripting

grep string and output filename

Hello, I have over 200 files and some of them have the string like "John price $200". I would like to grep the string. Then output the filename which found the string. I have the following script, but it ONLY output the string echo Please input list file name: read listn for file in `cat... (3 Replies)
Discussion started by: happyv
3 Replies

3. Shell Programming and Scripting

using grep and print filename

Hi, I have a question on bash. Basically I would like to print a file name using bash. I am actually trying to grep a particular character in sequential files. I have alot files such that a.txt, b.txt,c.txt...etc. If I found a certain character, I would print that particular filename. I... (5 Replies)
Discussion started by: ahjiefreak
5 Replies

4. Shell Programming and Scripting

How to search (grep?) filename for a string and if it contains this then...

Hi i want to write a script that will search a filename e.g. test06abc.txt for a string and if it contains this string then set a variable equal to something: something like: var1=0 search <filename> for 06 if it contains 06 then var1=1 else var1=0 end if but in unix script :) (4 Replies)
Discussion started by: tuathan
4 Replies

5. Shell Programming and Scripting

grep -A 1 "string" filename

Dear all, can anyone pls provide equivalent of below code for solaris system.? grep -A 1 "string" filename the above command is working for Linux system. but i need same command for Solaris system thanks (8 Replies)
Discussion started by: steve2216
8 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

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

8. Shell Programming and Scripting

Diff between grep .* file name and grep '.*' filename

Hi, Can anyone let me know what is difference between grep .* foo.c grep '.*' foo.c I am not able to understand what is exact difference. Thanks in advance (2 Replies)
Discussion started by: SasDutta
2 Replies

9. Shell Programming and Scripting

Regex for filename in grep

I want to print the filename keyword="XXTNL_AVSKRIV2ING" ftype="sql' I wan to search the keyword in all the sql files and the output shoul dbe filename:count grep -iwc "$keyword" *.$ftype | grep -v ":0$" But the output does not dispaly the filename which contains space as... (4 Replies)
Discussion started by: millan
4 Replies

10. UNIX for Dummies Questions & Answers

Usage of grep '^$1' filename

There is a file name list_filenames.dat, this has all the list of all files I need to encrypt, I did not understand what the following syntax is doing: grep -s "^$1" list_filenames.dat, when I manually run this command it just returns all the lines, what is the usage of this ? can someone... (4 Replies)
Discussion started by: okkadu
4 Replies
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 08:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy