Grep command construction


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep command construction
# 1  
Old 05-27-2014
Power Grep command construction

Hi,

I have an array variable "arr" that reads string from a file "vari.txt". Thus, the array will be of variable length depending how many entries are present in "vari.txt"

I use a for loop to traverse through the array.

However, i need a grep command to grep for a file "output.txt" and displays all the lines of output.txt except those that are present in the arrar arr.

I know how to traverse an array, grep -v and how to grep for multiple strings simultaneously.

Can you help me how could i achieve the grep command that displays all the lines of "output.txt" except those that are present in the arrar arr.

vari.txt (in this sample we have 4 entries, but it can have more or less entries i.e it varies)
Code:
Hello
Yellow
Home
Fellow

output.txt
Code:
The grass is Green.
Fellow, The color is Yellow.
I like to see you play.
i rang you up and said HELLO

The desired result should be:
Code:
The grass is Green
I like to see you play.


Last edited by mohtashims; 05-27-2014 at 06:57 AM..
# 2  
Old 05-27-2014
Hi, it could be done without an intermediate shell variable of array, like this:
Code:
grep -viFf vari.txt output.txt

Note the "case insensitive" -i, otherwise HELLO would not match Hello
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 05-27-2014
Quote:
Originally Posted by Scrutinizer
Hi, it could be done without an intermediate shell variable of array, like this:
Code:
grep -viFf vari.txt output.txt

Note the "case insensitive" -i, otherwise HELLO would not match Hello
Code:
grep -viFf vari.txt output.txt
grep: illegal option -- F
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

If i remove -F -f options i do not get the desired output. It displays all entries of output.txt.
Code:
SunOS mymac 5.10 Generic_150400-09 sun4v sparc SUNW,SPARC-Enterprise-T5220

Please help !!
# 4  
Old 05-27-2014
Try using /usr/xpg4/bin/grep rather than grep.
This User Gave Thanks to CarloM For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Web Development

Website construction nowaday!

Hello, Actually I am not sure how to ask this question, which is about the technique advance on website construction/design. Compared with HTML/CSS, which ones are the most popular for website construction? My colleague recommends Drupal for Linux platform. Any other? Thanks! Yifang (4 Replies)
Discussion started by: yifangt
4 Replies

2. Shell Programming and Scripting

case construction for basic Arithmetics calculation

the scrip (q4.sh) should perform the following calcuation (+, -, / and *) it should be used like this: q4.sh number1 operation number2 I wrote it already but the "*" does not work. #!/bin/bash #Date: 2010.10.19 # un script qui utilisera une instruction case pour effectuer des opérations... (6 Replies)
Discussion started by: flash80
6 Replies

3. Shell Programming and Scripting

Help with regex construction

I am trying to construct a regular expression that will filter a log file containing the following table: aP mP mC,mI oP oC oF oI tP tI hP ... (8 Replies)
Discussion started by: euval
8 Replies

4. Shell Programming and Scripting

Matrix construction

Hi I have to construct a rectangular matrix with 6012 rows and 2221 columns. Here the rows and columns were given by alphanumeric ids in a file named row.txt and column.txt respectively. with this row nd column ids I have to construct a matrix ie 6012*2221 and compare the column ids with... (0 Replies)
Discussion started by: riyabio
0 Replies

5. Shell Programming and Scripting

Matrix construction

Hi experts How to construct a rectangular matrix for a text file with 6012 rows and 2221 columns. Thank You (1 Reply)
Discussion started by: riyabio
1 Replies

6. Cybersecurity

Password Construction

Could someone please help, I am new to unix and I am trying to do the following: o Each password must have at least eight characters. Only the first eight characters are significant. PASSLENGTH is found in /etc/default/passwd and is set to 6. ... (1 Reply)
Discussion started by: tumbikikani
1 Replies
Login or Register to Ask a Question