Escaping backslash and asterisk in egrep to match "\*"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Escaping backslash and asterisk in egrep to match "\*"
# 8  
Old 03-01-2013
Quote:
Originally Posted by matthewfs
sorry the /* is wrong it should be \* and its "\*" a string. I will run the command and check it out (the od -c command)

---------- Post updated at 12:25 PM ---------- Previous update was at 12:04 AM ----------

So i found out the output of
Code:
echo "$domain"|od -c

is
Code:
0000000   *  \n
0000002

which is right because i am trying to pass an asterisks as the first parameter when i call my script. But when the script runs , checks the parameter and get to the asterisk part of my if statement, it does not go through. Here is the part of the if statement that check for the asterisks
Code:
elif [ "$(echo $domain | egrep '^\\*$')" != "" ]; then
        checkItem

I know the whole if statement whole because for every other condition i get the right output. BUt when i enter a asterisks as a parameter, checkItem function does not get called. I have a feeling its the regular expression.
OK. So domain contains the single character asterisk (*), but your code is looking for a backslash and an asterisk (\*).
So, the simple way to get what you want is:
Code:
if [ "$domain" = '*' ]
then    checkItem
fi

If you want to make it less efficient and use grep or egrep, that would be:
Code:
if [ "$(echo "$domain" | grep '^[*]$')" != "" ]
then    checkItem
fi

# 9  
Old 03-01-2013
Ok Don. I used the '*' way and it works now. Thanks you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search file containing ps results for a match "my.cnf" and then for a second match . "ok:" and

I need to find two matches in the output from ps. I am searching with ps -ef |grep mysql for: my.cnf /bin/sh /usr/bin/mysqld_safe --defaults-file=/data/mysql/master/agis_core/etc/my.cnf after this match I want to search back and match the hostname which is x number of lines back, above the... (2 Replies)
Discussion started by: bash_in_my_head
2 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Advanced & Expert Users

AIX - io info get from "libperfstat" not match "iostat"

Hi, everyone. I need to write a program to get io info based on libperfstat. But the "write time" of a disk is just half of the value get from iostat. I'm confused and can't explain. Help please. How I calculate "write service time per sec": In iostat: write service... (0 Replies)
Discussion started by: jackliang
0 Replies

4. UNIX for Dummies Questions & Answers

Egrep confusion with "I" and "-I" pattern

I am executing following command egrep -w I filename.txt the filename.txt has following data .... -I 07-18 08:31:19.924 9880 6 SessionManager ConnectConfig: ConfigurationWebService LoginResults=SuccessfulLogin I am so hungry that I need to eat I expect egrep to print only the second... (1 Reply)
Discussion started by: VBG
1 Replies

5. Shell Programming and Scripting

sed command escaping backslash "/"

Hello friends/'unix experts', i have a file as below cat sample.txt satish /rakesh/ sandhya /sandeep/ i have to replace /rakesh/ with rakesh, how can i do it with sed, i tried below code but its throwing errors sed -e 's/'"\(/rakesh/)\"'/\1rakesh/g' sample.txt ... (1 Reply)
Discussion started by: only4satish
1 Replies

6. Shell Programming and Scripting

Disabling Backslash Interpretation with "echo -E"?

Hello All, In a Bash Script I'm writing I have a section where I loop through a text file that was outputted by another script. In the text file some of the strings in there are enclosed with the BOLD "character sequences" (i.e. "\033But it's weird, because if I run this command: echo -E... (12 Replies)
Discussion started by: mrm5102
12 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

How to use the "grep/egrep" command to search files.

Hi Team, I am new to this forum and also trying to learn Unix. I will highly appriciate your help if you can help me to get the right command . {{{ I use the command " today | egrep '(10:| 11: )' | grep ERROR " to grep all the files that has been error betweeen 10 to 11... (6 Replies)
Discussion started by: rkhanal
6 Replies

9. UNIX for Dummies Questions & Answers

search ")" with egrep - egrep: syntax error

Hi Guys, we have a shell script which basically query the Database which retrieves huge data and use the data with "egrep" . Now there is some data which contains characters like "abc)" and the same is used like below : "egrep (.+\|GDPRAB16\|GDPR/11702 96 abc)\|$ temp.txt" now while... (7 Replies)
Discussion started by: sagarjani
7 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question