Grep on multiple parameters


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep on multiple parameters
# 1  
Old 05-21-2007
Grep on multiple parameters

All,

Is is possible to grep on two parameters in a file:

ex: If data in a file(GROCERIES.TXT) were like this

ABC GROCERIES 38-904949 16 987.89


Then grep would be

grep '38-904040' '16' GROCERIES.TXT

Thanks
KP
# 2  
Old 05-21-2007
If you want to get only those lines which have both '38-904040' and '16' you could do it with piping..

grep '38-904040' GROCERIES.TXT | grep '16'
# 3  
Old 05-21-2007
If your version of grep supports, you can try:

grep -e
# 4  
Old 05-21-2007
Code:
$ awk '$0 ~ /38-904949/ && $0 ~ /16/ 1;' GROCERIES.TXT

Cheers
ZB
# 5  
Old 05-21-2007
Quote:
Originally Posted by kingofprussia
All,

Is is possible to grep on two parameters in a file:

ex: If data in a file(GROCERIES.TXT) were like this

ABC GROCERIES 38-904949 16 987.89


Then grep would be

grep '38-904040' '16' GROCERIES.TXT

Thanks
KP
egrep "first|second" file
# 6  
Old 05-21-2007
Quote:
Originally Posted by ghostdog74
egrep "first|second" file
This is "or", I'm sure the OP wants "and".

Cheers
ZB
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python passing multiple parameters to functions

Hi, I am a beginner in python programming. In my python script have a main function which calls several other functions. The main function gets its input by reading lines from a input text file. I call the main function for every line in input text file through a loop. def main(line): var1... (6 Replies)
Discussion started by: ctrld
6 Replies

2. Shell Programming and Scripting

Grep from multiple patterns multiple file multiple output

Hi, I want to grep multiple patterns from multiple files and save to multiple outputs. As of now its outputting all to the same file when I use this command. Input : 108 files to check for 390 patterns to check for. output I need to 108 files with the searched patterns. Xargs -I {} grep... (3 Replies)
Discussion started by: Diya123
3 Replies

3. Shell Programming and Scripting

Grep final set of parameters from fit.log gnuplot file

I would like to grep the final set of fit parameters from a gnuplot log file to form columns that look like this. a_1001 b_1001 x_1001 a_1002 b_1002 x_1002 a_1003 b_1003 x_1003 . . . . . . . . . a_1250 b_1250 c_1250 At... (8 Replies)
Discussion started by: kayak
8 Replies

4. UNIX for Dummies Questions & Answers

Add multiple parameters to environment file

Hi, I am connecting to oracle DB from a unix script and below is how I am logging in with the parameters. this works fine, but the script connects to the DB thrice in different places and everytime these parameters have to be mentioned... which increases the lines in my script. In order to... (1 Reply)
Discussion started by: Vijay81
1 Replies

5. UNIX for Dummies Questions & Answers

Use of grep with multiple parameters in shell scripts

I am learning how to write shell scripts and have come across an issue. I'm trying to write a script that looks for a directory called public_html, and if it finds one, to print the number of lines that contain applet tags (containing '<applet') in all files that end in either .html or .htm that... (7 Replies)
Discussion started by: feverdream
7 Replies

6. Shell Programming and Scripting

Question on passing multiple parameters in if

Hi All, My target is to find the list of orphan processes running and i issue the below command with some exception ids. ps -ef | egrep -v "root|system|admin" | awk '{if ($3 == 1) print $1",\t"$2",\t"$3}' but this will exclude the process having the word 'root' and executing under different... (1 Reply)
Discussion started by: Arunprasad
1 Replies

7. Shell Programming and Scripting

bash if loop for checking multiple parameters

Hello, I've got next problem: I want to examine at the beginning of a script in an if loop that: 1. Is there 4 parameters given 2. If first state is true then: is there switches -e and -d? 3. At the end, how can i indentify them as variebles regardlees to its order. I was thinking like... (2 Replies)
Discussion started by: szittyafergeteg
2 Replies

8. Shell Programming and Scripting

Passing parameters to Shell script for GREP command

I am using grep to capture date from a file . Since i need to use the shell script for different dates ,is it possible to pass the date parameter to the shell script the Script is as below grep -E "08 Aug 2008|2008-08-08"* somefile.txt>test.txt The above script file greps the... (1 Reply)
Discussion started by: sud.tech
1 Replies

9. Shell Programming and Scripting

passing multiple files as parameters

hi all i am etl guy i have shell script that i use to do processing on file. the problem is that i want it to use on multiple files at same time is there any way of passing the file name since my all my filename start with samename like abc* p,ease let me know (4 Replies)
Discussion started by: er_zeeshan05
4 Replies

10. Shell Programming and Scripting

for loop logic with multiple parameters

hi, unix wizards, i have a question about the logic of my inner for loop below. first, what i am trying to do is to write a script called create_account that automatically creates mysql accounts. the user can provide a user_name or a group_id as an argument (and the script can take multiple... (1 Reply)
Discussion started by: ankimo
1 Replies
Login or Register to Ask a Question