How to grep value with "xxx"


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to grep value with "xxx"
# 1  
Old 11-11-2010
How to grep value with "xxx"

Hi,

I don't know how to grep two value with "" in the file, anyone can help?

for example:
the text file
John cash "1234" "ok"
may card "1245" "unknown"
John card "4567" "ok"
may cash "1111" "ok"
may card "1234" "ok"
peter card "1234" "ok"
John card "1234" "ok"

I would like to grep two value is card "1234" and "ok" together, the result will be:
may card "1234" "ok"
John card "1234" "ok"
# 2  
Old 11-11-2010
Code:
grep 'card "1234" "ok"' file | sort | uniq

Code:
sort file | uniq | grep 'card "1234" "ok"'


Last edited by ctsgnb; 11-12-2010 at 09:26 AM..
# 3  
Old 11-11-2010
Thx, but the output is empty...
SmilieSmilie
# 4  
Old 11-12-2010
Hi,
Just check with the placing of the right quotes for grep command. The pattern should always be enclosed in double quotes.
# 5  
Old 11-12-2010
Quote:
Originally Posted by happyv
Thx, but the output is empty...
SmilieSmilie
for me it works :
Code:
[ctsgnb@shell ~]$ cat tst1
John cash "1234" "ok"
may card "1245" "unknown"
John card "4567" "ok"
may cash "1111" "ok"
may card "1234" "ok"
peter card "1234" "ok"
John card "1234" "ok"
[ctsgnb@shell ~]$ grep 'card "1234" "ok"' tst1
may card "1234" "ok"
peter card "1234" "ok"
John card "1234" "ok"
[ctsgnb@shell ~]$ grep 'card "1234" "ok"' tst1 | sort -r
peter card "1234" "ok"
may card "1234" "ok"
John card "1234" "ok"
[ctsgnb@shell ~]$ grep 'card "1234" "ok"' tst1 | sort -r | uniq | tail -2
may card "1234" "ok"
John card "1234" "ok"
[ctsgnb@shell ~]$

This User Gave Thanks to ctsgnb For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

2. AIX

echo $varibla | mail -s "subject" "xxx@xxx.com" not ruuning as expected

Hi Folks, As per the subject, the following command is not working as expected. echo $variable | mail -s "subject" "xxx@xxx.com" Could anyone figure it out whats wrong with this. I am using AIX box. Regards, (2 Replies)
Discussion started by: gjarms
2 Replies

3. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

4. AIX

"fuser -c -k /XXX/XXXXXXX" Fails and stuck on AIX 6100-05-01-1016

Hi I was wondering if anybody has come across in a failure of fuser command. We have a backup script that is: fuser -c -k /XXX/XXXXXXX sync;sync umount /XXX/XXXXXXX/ backup -0 -f /dev/rmt0.1 -u /dev/XXXXXXXlv mount /XXX/XXXXXXX/ sync;sync The script is called from crontab via an... (2 Replies)
Discussion started by: ggovotsis
2 Replies

5. Shell Programming and Scripting

Compiling multiple ".c" files starting with xxx

Hello, I am trying to figure out how I can write a bashscript that compiles several ".c" files that start with xxx (example: xxx_try.c and xxx_that.c) So I want to compile all these files with a bash script. Anyone can help pls? (6 Replies)
Discussion started by: Freak79
6 Replies

6. Shell Programming and Scripting

Script for delete tmp files older than 15 days and owned by "xxx" id

Hi All , I want to delete files from /tmp directory created by "xxxx" id. because i got the list says more than 60 thousand files were created by "xxxx" id since 2002. The /tmp directory has lot of files created by different user ids like root,system etc.. But, i need a script to... (2 Replies)
Discussion started by: vparunkumar
2 Replies

7. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

8. HP-UX

ld: (Warning) Symbol "XXX" is not exported but is imported by a shared

Hi, I am trying to build the package for my build tree built with HP UX ecom compiler. I added the flags +check=all to enable run time checks. I compile the tree successfully, but while making the packages I am getting following error: === vxms tests = Generating pgncpio ld: (Warning)... (5 Replies)
Discussion started by: prits31
5 Replies

9. Shell Programming and Scripting

ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt"

Hi, I don't know hot to make this command work: ls -laR | grep "^-" | awk '{print $9}'| grep "$.txt" It should return the list of file .txt It's important to search .txt at the end of the line, becouse some file name have "txt" in their name but have other extensions (13 Replies)
Discussion started by: DNAx86
13 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