Matching exact string with blank space using grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Matching exact string with blank space using grep
# 1  
Old 10-23-2010
Matching exact string with blank space using grep

hi!

i'm trying to get grep to do an exact match for the following pattern but..it's not quite working. I'm not too sure where did I get it wrong. any input is appreciated.

Code:
       

echo "$VAR" | grep -q '^test:[[:space:]]name'
	if [ $? -eq 1 ]; then
printf "test name is not found \n"

    fi

on
solaris 5.10
# 2  
Old 10-23-2010
What is not working? Did you use /usr/xpg4/bin/grep ?
# 3  
Old 10-23-2010
Quote:
Originally Posted by Scrutinizer
What is not working? Did you use /usr/xpg4/bin/grep ?
hi! could you explain the differences between /usr/bin/grep and /usr/xpg4/bin/grep? will there be any script portability issue?

and would it correct to map it this way?

Code:
#!/bin/sh
grep=/usr/xpg4/bin/grep

# 4  
Old 10-23-2010
See man grep on Solaris. The xpg4 version has a -q option.

What do you mean map? This puts it in the variable $grep
You could do this:
Code:
#!/bin/sh
export PATH="/usr/xpg4/bin:$PATH"

Actually, I reckon this would be a good way to start a script on Solaris:
Code:
#!/usr/xpg4/bin/sh
export PATH="/usr/xpg4/bin:$PATH"

Using XPG4 is the closest you can come to Posix compliance and should give you good portability. You would likely only need to change the shebang (#!) on the first line if you want to run it on another platform.

Last edited by Scrutinizer; 10-23-2010 at 10:20 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 10-23-2010
Thanks! You're the man!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep to find an exact string

Hi all, I tried searching the forum for this, and I read numerous suggestions here and even on other forums, and I cannot get this to want the way that I need it to. I tried grep -W / -f to no luck. Here is what I have. I have a list of file names- FILE1-FILE1TEST,FILE1RELATION... (7 Replies)
Discussion started by: jeffs42885
7 Replies

2. Shell Programming and Scripting

Grep exact string from main string

Hi , am getting output file, it sontains the below values. ./hawk_DOM1_FIRST_ENV ./hawk_DOM2_SECOND_ENV ./hawk_DOM3_THIRD_ENV Now I need to grep the word "DOM1_FIRST_ENV","DOM2_SECOND_ENV" like that. I tired with cut -d "_". Its not working with any deleimiter. Can you please help to... (3 Replies)
Discussion started by: ckchelladurai
3 Replies

3. 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

4. Shell Programming and Scripting

grep to remove blank space

Hi All, Need help to grep blank and copy to file. I have a file in below format dns1dm06_10, dns2dm02_04, dbidub,10000000c9a46d0c gbpuhci,10000000c948b00a ibtur001,10000000c9a1ccda yubkbtp1,10000000c93fec5b I need to copy to all lines which doesn't have wwn >> no-wwn.txt 1... (2 Replies)
Discussion started by: ranjancom2000
2 Replies

5. UNIX for Dummies Questions & Answers

How to grep the exact string / word ?

Hi All, I have a text / log file which contains strings like meta777, 77, meta, 777. Now I want to write a script which can detect a string 'meta#777' in a text file & number of occurence of 'meta', number of #, number 7, 77, 777. I'm using grep -e '77' filename but no luck. It is returning... (5 Replies)
Discussion started by: adc22
5 Replies

6. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

7. Shell Programming and Scripting

Select the exact matching contents using grep

Hi everyone I've two files.. The contents of file1 are as shown below 4 5 12 13 36 37 45 46 47 The contents of file2 are as shown below 21 hello 13 world (5 Replies)
Discussion started by: abk07
5 Replies

8. Shell Programming and Scripting

String starting with blank space

Dear Masters, Need your help for this small query. I am trying to get all the strings that starts with a blank space as output. Limitation is , it should be done only through AWK. Input will be: aa _1bbb c-ccc ddd eeeee ff Output should be: _1bbb c-ccc eeee ff (5 Replies)
Discussion started by: patric2326
5 Replies

9. Shell Programming and Scripting

How to use grep to get an exact string?

Hi there, I've search this forum and find this problem could have been solved by, grep -ho "num=*" input_data The input_data is, 1\11\num1=100\num2=200\newnum1=220\\@ however, what I have got is , num1=100 num1=220 how to get the exact string, (4 Replies)
Discussion started by: liuzhencc
4 Replies

10. UNIX for Dummies Questions & Answers

how to grep for blank records (space,tab,/n)?

I want to exclude (-v) blank records from a file before analysing it. I know I can use '^]$' for spaces and tabs but how do you look for lines that have nothing (/n or line feed) ? (2 Replies)
Discussion started by: Browser_ice
2 Replies
Login or Register to Ask a Question