grep multiple matches


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers grep multiple matches
# 1  
Old 01-29-2011
grep multiple matches

i dun seems to be able to grep the arguments i want.

eg. book.txt with description inside.

ABC:efg:5:6
HHH:JJJ:6:7

i want the user to input the book title and author they want. so when the user enters book title ABC and book author efg, they print out exact match of ABC:efg:5:6. Caps do matters here. Anyone can help?
# 2  
Old 01-29-2011
Help us to help you ... post your code !
what have you tried so far ?
Code:
$ echo "ABC:efg:5:6" | { IFS=: read a b c d ; echo "title:$a author:$b edition:$c whatever:$d" ; }
title:ABC author:efg edition:5 whatever:6
$ echo "ABC:efg:5:6" | { IFS=: read a b c d ; echo "title:$a\nauthor:$b\nedition:$c\nwhatever:$d" ; }
title:ABC
author:efg
edition:5
whatever:6
$

# 3  
Old 01-29-2011
Code:
echo "Book name: "
read book
echo "Author name: "
read author
awk '/'"$book"'/&&/'"$author"'/' book.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get index values for multiple matches in the same line with awk?

Hi, I know that echo "bob alice robert alice" | awk '{print index($0,"alice")}' 5Will output the index of the first alice match, is there any way to get the index of all matches?, eg: echo "bob alice robert alice" | awk 'unknown magic' 5:18Thanks for your time. (6 Replies)
Discussion started by: chilicuil
6 Replies

2. Shell Programming and Scripting

Grep -w not printing exact matches

Dear All, Here is my input TAACGCACTTGCGGCCCCGGGATAAAAAAAAAAAAAAAAAAAAATGGATT NAGAGGGACGGCCGGGGGCATAAAAAAAAAAAAAAAAAAAAAGGGATTTC NGGGTTTTAAGCAGGAGGTGTCAAAAAAAAAAAAAAAAAAAAAGGGATTT NTGGAACCTGGCGCTAGACCAAAAAAAAAAAAAAAAAAAATGGATTTTTG ATACTTACCTGGCAGGGGAGATACCATGATCAATAAAAAAAAAAAAAAAA... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. Shell Programming and Scripting

finding matches between multiple files from different directories

Hi all... Can somebody pls help me with this... I have a directory (dir1) which has many subdirectories(vr001,vr002,vr003..) with each subdir containing similar text file(say ras.txt). I have another directory(dir2) which has again got some subdir(vr001c,vr002c,vr003c..) with each subdir... (0 Replies)
Discussion started by: bramya07
0 Replies

4. Shell Programming and Scripting

How to take out multiple matches in file2 using file1 as a reference?

Hi guys, As the title, I want to take out the lines in file2 if the TCONS_* matches that in file1. Then put the lines in a file3. The TCONS numbers ranges from TCONS_00000024 to TCONS_00381684. Those numbers are continuous in file2, not in file1. Below is just some lines of file1 and file2 ... (4 Replies)
Discussion started by: lyni2ULF
4 Replies

5. Shell Programming and Scripting

grepping multiple matches in a single string

Hi All, I'm trying to grep for 3 patterns in a string of gibberish. It so happens that each line is appended by a date/time stamp and i was able to figure out how to extract only the datetime. here is the string.. i have to display tinker tailor soldier spy Please can some help... (2 Replies)
Discussion started by: Irishboy24
2 Replies

6. Shell Programming and Scripting

Using grep returns partial matches, I need to get an exact match or nothing

I’m trying to modify someone perl script to fix a bug. The piece of code checks that the zone name you want to add is unique. However, when the code runs, it finds a partial match using grep, and decides it already exists, so the “create” command exits. $cstatus = `${ZADM} list -vic | grep... (3 Replies)
Discussion started by: TKD
3 Replies

7. Shell Programming and Scripting

find/grep returns no matches

Hi all! I've faced with very unintelligible error using find/grep like this: root@v29221:~# find /var/www/igor/data/www/lestnitsa.ru | grep u28507I get nothing as a result, but: root@v29221:~# grep u28507 /var/www/igor/data/www/lestnitsa.ru/_var.inc $db_name = 'u28507';... (2 Replies)
Discussion started by: ulrith
2 Replies

8. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies

9. Shell Programming and Scripting

Grep regex matches, groups

Hello, I am searching all over the place for this, just not finding anything solid :( I want to do be able to access the groups that are matched with grep (either with extended regex, or perl compatible regex). For instance: echo "abcd" | egrep "a(b(c(d)))" Of course this returns... (1 Reply)
Discussion started by: Rhije
1 Replies

10. Shell Programming and Scripting

Appending Text To Each Line That Matches Grep

I'm currently digging for a way to append a line to a text file where each line begins with the word "setmqaut". This is a continuation of my IBM MQSeries backup script I'm working on to make my life a little easier. What I would like to do is have each line that looks like this: setmqaut -m... (4 Replies)
Discussion started by: sysera
4 Replies
Login or Register to Ask a Question