how to get the string stored in a variable in a line???
Hi all,
I want to search for a data type in a line.For this in a loop i am checking for $DATA_TYPE in a line using grep.But grep is not able to find when i give this.
Can any one tell me how to check string in $DATA_TYPE variable in line usign grep (or) any other way to do the above task.
declare -a TYPES_LIST
declare -a EXIST_FLAG=0
TYPES_LIST[0]="char"
TYPES_LIST[1]="int"
TYPES_LIST[2]="float"
TYPES_LIST[3]="double"
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
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)
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)
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)
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)
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)
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)
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)
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)
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 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)