The problem with your script is the use of a literal dollar sign in the regular expression; this is a special character, which means "end of line" to grep. You can escape it by prefixing it with a backslash, or (like you alrady did with the asterisk) by putting it in a character class. Also you seem to be missing a closing single quote.
The motions to run grep in backticks and then examine the output are redundant, you can just run [ef]grep in the if directly.
grep cannot (typically) grep for multiple things, but you can look at egrep or fgrep if you want to simplify your script.
grep (without -c or -q) prints the matching line as a matter of course, so you don't need to do that separately.
Even the break (and thus the whole if, and the whole for loop) is redundant if you use egrep or fgrep to look for all the possibilities in one go.
Last edited by era; 04-05-2008 at 12:05 PM..
Reason: CODE tags don't like space between [$] and [*], duh
Hi all,
I have a variable say var1 (output from somewhere, which I can't change)which store something like this:
echo $var1
name=fred
age=25
address="123 abc"
password=pass1234
how can I make the variable $name, $age, $address and $password contain the info?
I mean do this in a... (1 Reply)
Hallo!
Example.
#!/bin/bash
BACKUP_DIR=/home/userx/backups/evolution
echo $BACKUP_DIR
# delete the first character from the string
BACKUP_DIR=$(echo $BACKUP_DIR | cut -c 2-)
echo $BACKUP_DIR
It works. It does want I want, delete the first character from string in the... (11 Replies)
Hi ,
I want to read below output, lets called it output1.txt and each string for every line will be declare as a variables.
This is the input file
196 server_a server_unix_2 FW
196 server_b server_win_1 CD
196 server_c server_win_2 CD
196 server_bd ... (2 Replies)
can anyone please help me with this:
i have written a shell script and a stored procedure which has one OUT parameter. now i want to use that out parameter as an input to the unix script but i am getting an error as variable not found. below are the unix scripts and stored procedure...
... (4 Replies)
I have two variables,
my $filename = "abc_yyyy_mm_dd.txt";
my $filename1 = " abc_2011_11_07.txt";
I need to perform some operations after checking if $filename has $filename1 in it
i have used the below code,
if($filename =~ /^$filename1/)
{
----
--
} (2 Replies)
I need to remove double quoted strings from specific lines in a file. The specific line numbers are a variable. For example, line 5 of the file contains
A B C "string"
I want to remove "string". The following sed command works:
sed '5 s/\"*\"//' $file
If there are multiple... (2 Replies)
Greetings Experts,
As part of automating the sql generation, I have the source table name, target table name, join condition stored in a file join_conditions.txt which is a delimited file (I can edit the file if for any reason). The reason I needed to store is I have built SELECT list without... (5 Replies)
Hi
I have the follwoing requirement
I have a file as follows:
# cat priy
yyy.poweroff_cmd = /sbin/poweroff
hhh.powersave-nap = 1
When this file is provided as input, I first used "awk" command and saved variables present after "="
replace=$line
replace1=`echo $line | awk -F "="... (3 Replies)
The bash bash below extracts the oldest folder from a directory and stores it in filename
That result will match a line in bold in input. In the matching line there is an_xxx digit in italics that
(once the leading zero is removed) will match a line in link. That is the lint to print in output.... (2 Replies)
For example: I am grepping "Hello" from a file and there are 10 matches. So all ten lines with match will get stored into a variable($match). Now I want to ignore those lines which have "Hi" present in that.
Currently I tried this: match = grep "Hello" file | grep -v "Hi" file
But that's not... (2 Replies)
Discussion started by: pavan
2 Replies
LEARN ABOUT LINUX
zegrep
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)