Issues in grep command in Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues in grep command in Linux
# 1  
Old 01-16-2012
Issues in grep command in Linux

Hi All

I have a file containing following records:
Code:
$HEW_TGT_DB2_USER=hbme_bi2
$prmAttunityUser=ais
$DS_USER=hbme_bi2
$prmStgUser=hbme_bi2
$prmuser=hbme_bi2
$prmStgPass=hbme_bi2
$prmpwd=hbme_bi2
$prmAttunityUser=ais

Say suppose the name of the file is test4.txt

When i fire this command on linux
Code:
ret=`grep \^$prmAttunityUser\= test4.txt`
echo $ret

The value in "ret" is blank could you all please help me in troubleshooting this where as i want that "ret" variable should contain output like this

Code:
$prmAttunityUser=ais




Thanks
# 2  
Old 01-16-2012
Code:
#ret=$(grep '$prmAttunityUser\=' test4.txt )
#echo $ret
#$prmAttunityUser=ais $prmAttunityUser=ais

# 3  
Old 01-16-2012
Code:
ret=$(grep \$prmpwd <file name>)

You need to escape $
This User Gave Thanks to dirtyd0ggy For This Post:
# 4  
Old 01-17-2012
I want the output as
Code:
prmAttunityUser=ais

The output should be excluding the $ sign.
# 5  
Old 01-17-2012
if you want something like

$DS_USER should be hbme_bi2
$prmAttunityUser should be ais


then you need to read about the command source or ( . )

Code:
 
$ cat test.txt
a=one
b=two
c=three
 
$ . test.txt
 
$ echo $a
one
 
$ echo $b
two
 
$ echo $c
three

# 6  
Old 01-17-2012
Similar post : https://www.unix.com/shell-programmin...rep-issue.html

Please continue with the link ..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep command in Linux in a script where the search string has a space

I have a file xyz with the following content PPPL 0123 PPPL 0006 POFT 0923 POFT 1111 WENT 2323 SEND 2345 I also have another file named MasterFile where it contains the above mentioned data million times with different digits at the end for example some times it contains SEND 9999 or WENT... (4 Replies)
Discussion started by: knijjar
4 Replies

2. UNIX and Linux Applications

Xalan & Xerces issues for Oracle Linux 6.6 & Solarisstudio12.3 C++ compiler for Linux

Hi Team, I am facing issue while using Xalan & Xerces for my application. Below are my environment details i am using :- Platform:- Oracle Linux 6.6 Compiler :- solarisstudio12.3 C++ compiler for Linux Below are the versions of Xalan & Xerces source code used to build the shared object... (0 Replies)
Discussion started by: agrachirag
0 Replies

3. Red Hat

Echo and grep issues

Is there an environment issue that would not allow the following not store and pass the value into this field: underScorePresent=`echo $USER | grep "_" | wc -l` It is running on a new redhat 6.5 OS. The value $USER is set to cpac. It is a vendor code and they are saying it is environment... (1 Reply)
Discussion started by: mrn6430
1 Replies

4. Red Hat

Linux Bind mount issues.

Hi All, we have an issue in bind mounting LINUX. we are able to see the bound mounts in mount command and df -h <file system name> but they are not visible in normal df -h command. all these mounts are local mounts. we have a /xyz is mount and abc is a directory in /xyz ( /xyz/abc ) ... (1 Reply)
Discussion started by: Naveen.6025
1 Replies

5. UNIX for Dummies Questions & Answers

Issues while pattern matching using grep

Hi, I have a file f1 wi the following data f1.txt ======== Report ID Report Name ----------------------------------------------------------------- Post Requests : 2 Post successes : 2 ============================================= I need to search for the... (2 Replies)
Discussion started by: RP09
2 Replies

6. Shell Programming and Scripting

Grep command showing wrong output in Linux

Hi All I am trying to run a script in linux wherein i have a command like this grep ^prmAttunityUser= djpHewr2XFMAttunitySetup_ae1_tmp djpHewr2XFMAttunitySetup_ae1_tmp is a temporary file in which the user value is stored but this command in the script returns me balnk value whereas it has a... (4 Replies)
Discussion started by: vee_789
4 Replies

7. UNIX for Advanced & Expert Users

grep -ip command in Linux

Hi, As you know we can capture paragraph information using -ip command with grep option in AIX and other OS. Is there anything similar to this command in linux to capture paragraph infroamtion? coammnd: cat a.out | grep -ip "Word1" Thanks ---------- Post updated at 07:38 PM... (4 Replies)
Discussion started by: NARESH1302
4 Replies

8. Shell Programming and Scripting

Issues with grep -w

I am trying to use grep -w something as shown below. grep -w "$a" $LOG1 It is not giving me neither any error nor any data. I am facing the issue while i run this command inside a script. But i am getting the data if i run the above command outiside the script. here $a=08/11/2009 21 i... (13 Replies)
Discussion started by: rdhanek
13 Replies

9. Shell Programming and Scripting

Solaris / Linux Issues with script

Hello, I run this command from a solaris box and it works just fine. It gives me the kind of output in my file I am looking for which would be for example... sb1p rdop ot2p ot3p eimp However when I do the same thing from a Linux box... ps -ef | grep nco_p_syslog | grep -v grep |... (19 Replies)
Discussion started by: LRoberts
19 Replies

10. UNIX for Dummies Questions & Answers

GREP issues

Hi all, I am trying to perform a simple task with grep, this is what I execute: grep -i -n 'error|fail|warning' cl_less.out when I execute it it does not give any errors, as in the command worked and back to the command prompt, but if I run each grep independently the I do get a real fail: ... (8 Replies)
Discussion started by: sqloyd
8 Replies
Login or Register to Ask a Question