Sponsored Content
Top Forums Shell Programming and Scripting how to fgrep -f two files and get only one instance of each matched line Post 302573925 by smarones on Wednesday 16th of November 2011 05:11:03 AM
Old 11-16-2011
how to fgrep -f two files and get only one instance of each matched line

Hello,

I have two files:

Code:
 
file1
x
v
r
g
 
file2 
 
aaaa,x,1111
bbbb,v,2222
bbbb,v,
cccc,r,3333
dddd,s,4444
eeee,q,5555
ffff,p,6666
 
output
 
aaaa,x,1111
bbbb,v,2222
cccc,r,3333
 
and not
 
aaaa,x,1111
bbbb,v,2222
bbbb,v,
cccc,r,3333

fgrep -f file1 file2 gives me what I dont want

Thanks,

Last edited by smarones; 11-16-2011 at 06:20 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get a next line of a matched word?

Hi , If I match a word in a file, I want to pick the next line of that matched word. My file is a below format- The ntrag trace has auditError Line5005 contains transaction Ntrag data ------------ Here I wanted if I match a word auditError, I need to get the next line "Line5005... (10 Replies)
Discussion started by: Muktesh
10 Replies

2. Shell Programming and Scripting

replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything! (3 Replies)
Discussion started by: IronHorse7
3 Replies

3. Shell Programming and Scripting

awk script to move a line after the matched pattern line

I have the following text format in a file which lists the question first and then 5 choices after that the explanantion and finally the answer. 1.The amount of time it takes for most of a worker’s occupational knowledge and skills to become obsolete has been declining because of the... (2 Replies)
Discussion started by: nanchil_guy
2 Replies

4. Shell Programming and Scripting

Append instance count to each line

Hello forum, I need help with a script for displaying the number of instances/times a particular line appears in a tab-delimited file and append that number to the end of the line. Example text file: aaa bbb ccc ddd ggg hhh kkk nnn aaa bbb ccc ddd aaa bbb ccc ddd ppp qqq nnn sss ggg... (1 Reply)
Discussion started by: jaysean
1 Replies

5. Shell Programming and Scripting

awk get matched line's previous line

hi everyone, a b in c d e f in g output is: a e so awk search for "in", then print out the matched line's previuos line. Please advice. (11 Replies)
Discussion started by: jimmy_y
11 Replies

6. Shell Programming and Scripting

Replace all but skip first instance in a line

I have a record like the one given below. 010000306551~IN ~N~ |WINDWARD PK|Alpharetta| If ~ is present more than instance in a line,then I need to delete those instances. Any ideas? I am working in Solaris (7 Replies)
Discussion started by: prasperl
7 Replies

7. Shell Programming and Scripting

Using sed can you specify the last instance of a character on a line?

I was told a way to do this with awk earlier today but is there a way with sed to specify the last instance of a character on a line? You will know what character you're looking for but there could be none or one hundred instances of it on a line say and you ONLY want to specify the last one for... (3 Replies)
Discussion started by: Bashingaway
3 Replies

8. Shell Programming and Scripting

Help required on joining one line above & below to the pattern matched string line.

Hi Experts, Help needed on joining one line above & below to the pattern matched string line. The input file, required output is mentioned below Input file ABCD DEFG5 42.0.1-63.38.31 KKKK iokl IP Connection Available ABCD DEFG5 42.0.1-63.38.31 ... (7 Replies)
Discussion started by: krao
7 Replies

9. Shell Programming and Scripting

awk line instance counter

I Have a text file with several thousand lines of text. Occasionally there will be a "sysAlive" line of text (every so often) What would be an awk command to print every line of text, and to put in incrementing counter ONLY on the "sysAlive" lines For example: >cat file.txt lineAAA a b c d... (4 Replies)
Discussion started by: ajp7701
4 Replies

10. Shell Programming and Scripting

How to print previous line of multiple pattern matched line?

Hello, I have below format log file, Comparing csv_converted_files/2201/9747.1012H67126.5077292103609547345.csv and csv_converted_files/22019/97447.1012H67126.5077292103609547345.csv Comparing csv_converted_files/2559/9447.1012H67126.5077292103609547345.csv and... (6 Replies)
Discussion started by: arvindshukla81
6 Replies
ZDIFF(1)                                                      General Commands Manual                                                     ZDIFF(1)

NAME
zcmp, zdiff - compare compressed files SYNOPSIS
zcmp [ cmp_options ] file1 [ file2 ] zdiff [ diff_options ] file1 [ file2 ] DESCRIPTION
Zcmp and zdiff are used to invoke the cmp or the diff program on files compressed via gzip. All options specified are passed directly to cmp or diff. If only file1 is specified, it is compared to the uncompressed contents of file1.gz. If two files are specified, their con- tents (uncompressed if necessary) are fed to cmp or diff. The input files are not modified. The exit status from cmp or diff is pre- served. SEE ALSO
cmp(1), diff(1), zmore(1), zgrep(1), znew(1), zforce(1), gzip(1), gzexe(1) BUGS
Messages from the cmp or diff programs may refer to file names such as "-" instead of to the file names specified. ZDIFF(1)
All times are GMT -4. The time now is 03:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy