Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Looping Logic, Need to implement Post 302848713 by Chubler_XL on Thursday 29th of August 2013 10:19:47 PM
Old 08-29-2013
There should be no need to populate an array, or use a counting variable (run).

The for loop will populate a variable (file in this case) with each filename and loop for you.

Here I use grep with -q (quiet) option to test for string a and set the exit status, this is used by the if statement:

Code:
for file in /path1/file*
do
   if grep -q a $file
   then
        echo "a is exist in $file"
   else
        echo "a is not exist in $file"
   fi
done

 

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Logic needed to recursive looping in the script

Hello i have a requirement where in a file i will get string. The length could be from 1 to 20. if the string is less than 6 characters ( ex: ABCD) . i need to append 'X' on right hand side to make it 6 characters (ex: ABCDXX). if suppose i get the same string from the file as ABCDXX then i... (5 Replies)
Discussion started by: dsdev_123
5 Replies

2. Shell Programming and Scripting

Need logic to implement file compare.

Hi all I have a requirement where i have to develop a file compare tool. Requirement: I have one expected file and one actual file. Both the files are database dumps in a csv file comma seperated. The first line of the file has the column names. Now there are 3 scenarios: 1) Firstly we have... (0 Replies)
Discussion started by: Ganesh_more
0 Replies

3. Shell Programming and Scripting

How to implement "not in" logic in UNIX script?

Hi Gurus, I need use "not in " logic in my script, like below if $name not in exception_file_list, then do something. anyone can help out this? Thanks in advance. (5 Replies)
Discussion started by: ken6503
5 Replies

4. Programming

Missing Logic Looping Through Switch Statement

Having trouble with the logic when looping over this switch case again: for (j = 0; data != 0; j++){ switch(data){ case 'c': output = ranit(r_brace_array); break; case 'h': output = ranit(pipe_array); break; ... (6 Replies)
Discussion started by: Azrael
6 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 12:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy