Sponsored Content
Top Forums Shell Programming and Scripting Compare one files with strings from another + remove lines Post 302582951 by sdf on Monday 19th of December 2011 06:27:07 AM
Old 12-19-2011
Compare one files with strings from another + remove lines

Have two files and want to compare the content of file1 with file2. When matched remove the line.
Code:
awk 'NR==FNR {b[$0]; next} !(b in $0)' file1 file2

file1
HTML Code:
1. if match
2. remove
file2
HTML Code:
1. this line has to be removed if match
2. this line has a match, remove
3. this line has no match, no removing
The code does not remove the matches.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Compare and Remove duplicate lines from txt

Hello, I am a total linux newbie and I can't seem to find a solution to this little problem. I have two text files with a huge list of URLS. Let's call them file1.txt and file2.txt What I want to do is grab an URL from file2.txt, search file1.txt for the URL and if found, delete it from... (11 Replies)
Discussion started by: rmarcano
11 Replies

2. Shell Programming and Scripting

Remove matching lines with list of strings

Hi, HP-UX gxxxxxxxc B.11.23 U ia64 3717505098 unlimited-user license I have a file with below pipe separated field values: xxx|xxx|abcd|xxx|xxx|xx xxx|xxx|abcd#123|xxx|xxx|xx xxx|xxx|abcd#345|xxx|xxx|xx xxx|xxx|pqrs|xxx|xxx|xx xxx|xxx|pqrs#123|xxx|xxx|xx The third field has values like... (6 Replies)
Discussion started by: Nanu_Manju
6 Replies

3. Shell Programming and Scripting

Compare two files and remove all the contents of one file from another

Hi, I have two files, in which the second file has exactly the same contents of the first file with some additional records. Now, if I want to remove those matching lines from file2 and print only the extra contents which the first file does not have, I could use the below unsophisticated... (3 Replies)
Discussion started by: royalibrahim
3 Replies

4. Shell Programming and Scripting

different take on common ?: search for two strings and remove lines between them

Thank you for assisting, I've got a partial solution just needs a tweak. Hulk-BASH$ cat somefile.txt oh there is some stuff here some more stuff here START_LABEL stuff I want more stuff I want END_LABEL other stuff here too and even more stuff here too Hulk-BASH$ Hulk-BASH$ sed... (8 Replies)
Discussion started by: laser
8 Replies

5. Shell Programming and Scripting

compare two files and to remove the matching lines on both the files

I have two files and need to compare the two files and to remove the matching lines from both the files (4 Replies)
Discussion started by: shellscripter
4 Replies

6. Shell Programming and Scripting

Compare two strings, and print lines containing mismatches

pls help me on this... and im really sorry because i really don't know where to start here... FILE1 ABC DEF 10 2 DEF GHI 11 3 GHI JKL 12 5 JKL MNO 13 7 MNO PQR 14 5 requirements: 1. The third string should only be 10 or 12 2. The fourth string should only be 2 or 3 3. Prinnt... (1 Reply)
Discussion started by: kingpeejay
1 Replies

7. Shell Programming and Scripting

Match strings in two files and compare columns of both

Good Morning, I was wondering if anybody could tell me how to achieve the following, preferably with a little commenting for understanding. I have 2 files, each with multiple rows with multiple columns. I need to find each row where the value in column 1 of file 1 matches column 1... (10 Replies)
Discussion started by: GarciasMuffin
10 Replies

8. Shell Programming and Scripting

compare files and then remove some lines

Hi everyone I have a dilemma and I'm hoping someone has an answer for me. I have two files: # cat masterfile line3 line4 line5 line6 line7 # cat tempfile line1 line2 line3 line4 I want to compare tempfile with masterfile. (3 Replies)
Discussion started by: soliberus
3 Replies

9. Shell Programming and Scripting

How to remove lines containing strings

Hi Guys, I need some script in removing lines containing strings like ",, ," and "rows". Retain only numbers as the output. See below for the input and output file. INPUT FILE: 9817 9832 6285 6312 6313 6318 ,, , 6329 7078 7098 7130 7959 7983 (7 Replies)
Discussion started by: pinpe
7 Replies

10. Shell Programming and Scripting

Remove lines containing 2 or more duplicate strings

Within my text file i have several thousand lines of text with some lines containing duplicate strings/words. I would like to entirely remove those lines which contain the duplicate strings. Eg; One and a Two Unix.com is the Best This as a Line Line Example duplicate sentence with the word... (22 Replies)
Discussion started by: martinsmith
22 Replies
MV(1)							      General Commands Manual							     MV(1)

NAME
mv - move or rename files SYNOPSIS
mv [ -i ] [ -f ] [ - ] file1 file2 mv [ -i ] [ -f ] [ - ] file ... directory DESCRIPTION
Mv moves (changes the name of) file1 to file2. If file2 already exists, it is removed before file1 is moved. If file2 has a mode which forbids writing, mv prints the mode (see chmod(2)) and reads the standard input to obtain a line; if the line begins with y, the move takes place; if not, mv exits. In the second form, one or more files (plain files or directories) are moved to the directory with their original file-names. Mv refuses to move a file onto itself. Options: -i stands for interactive mode. Whenever a move is to supercede an existing file, the user is prompted by the name of the file followed by a question mark. If he answers with a line starting with 'y', the move continues. Any other reply prevents the move from occur- ring. -f stands for force. This option overrides any mode restrictions or the -i switch. - means interpret all the following arguments to mv as file names. This allows file names starting with minus. SEE ALSO
cp(1), ln(1) BUGS
If file1 and file2 lie on different file systems, mv must copy the file and delete the original. In this case the owner name becomes that of the copying process and any linking relationship with other files is lost. 4th Berkeley Distribution April 29, 1985 MV(1)
All times are GMT -4. The time now is 01:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy