Sponsored Content
Top Forums Shell Programming and Scripting How can i delete the contents of one file based on another file Post 302348303 by panyam on Friday 28th of August 2009 01:31:08 AM
Old 08-28-2009
Not sure , why grep -v -f option is not working .

Try some thing like this :
Code:
awk 'NR==FNR { a[$0]=$0;b[++n]=$0;next } { if($0 in a) {a[$0]="";}} END { for (i=1;i<=n;i++) print a[b[i]] }' file1 file2 | sed '/^$/d'


Last edited by panyam; 08-28-2009 at 02:43 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looking for a perl script (windows) to delete the contents of a file

Hi All, Im having a file named logserver.txt. I want a perl script to take a backup of that file, along with the datestamp; move the file to a different location or empty the contents of the file after backup. Remember, the file gets generated when the related service starts. My condition is... (14 Replies)
Discussion started by: ntgobinath
14 Replies

2. Shell Programming and Scripting

Remove lines based on contents of another file

So, this issue is driving me nuts! I was hoping to get a lending hand here... I have 2 files: file1.txt contains: this is example1 this is example2 this is example3 this is example4 this is example5 file2.txt contains: example3 example5 Basically, I need a script or command to... (4 Replies)
Discussion started by: bashshadow1979
4 Replies

3. Shell Programming and Scripting

Delete block of text in one file based on list in another file

Hi all I currently use the following in shell. #!/bin/sh while read LINE do perl -i -ne "$/ = ''; print if !m'Using archive: ${LINE}'ms;" "datafile" done < "listfile" NOTE the single quote delimiters in the expression. It's highly likely the 'LINE' may very well have characters in it... (3 Replies)
Discussion started by: Festus Hagen
3 Replies

4. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

5. UNIX for Dummies Questions & Answers

count values based on contents of another file

Hello, I have two files as shown below: test1 678 679 689 690 710 test2 1 678 654 800 676 791 689 900 I want to get a count of lines from test2 whose columns bound the values in test1 I tried running the code below; however am getting wrong results. (3 Replies)
Discussion started by: Gussifinknottle
3 Replies

6. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

7. UNIX for Dummies Questions & Answers

find lines in another file based on contents in a second file

Hello, I have a file with tab delimited columns like: File1 A 2 C R F 4 D Q C 9 A B ...... I want to grep out the lines in a second file, File2, corresponding to each line in File1 Can I do this: while read a b c d do grep '$a\t$b\t$c\t$d' File2 >>... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

8. Shell Programming and Scripting

File comparison based on contents

Hi I have 2 files 1.del ---- 1,2,3,4,5 1,2,3,4,4 1,1,1,1,2 2.del ---- 1,2,3,4,5 1, 1,2,3,4,4 1,1,1,1,2 I need to compare the above two files in unix, as in the output should only tell the difference in contents as I should get only the line 1 ( from 2.del) , rest all lines are... (4 Replies)
Discussion started by: Ethen561
4 Replies

9. Shell Programming and Scripting

Remove or rename based on contents of file

I am trying to use the two files shown below to either remove or rename contents in one of those files. If in file1.txt $5 matches $5 of file2.txt and the value in $1 of file1.txt is not "No Match" then that value is substituted for all values in $5 and $1 of file2.txt. If however in $1 ... (5 Replies)
Discussion started by: cmccabe
5 Replies
SDIFF(1)							   User Commands							  SDIFF(1)

NAME
sdiff - side-by-side merge of file differences SYNOPSIS
sdiff [OPTION]... FILE1 FILE2 DESCRIPTION
Side-by-side merge of file differences. -o FILE --output=FILE Operate interactively, sending output to FILE. -i --ignore-case Consider upper- and lower-case to be the same. -E --ignore-tab-expansion Ignore changes due to tab expansion. -b --ignore-space-change Ignore changes in the amount of white space. -W --ignore-all-space Ignore all white space. -B --ignore-blank-lines Ignore changes whose lines are all blank. -I RE --ignore-matching-lines=RE Ignore changes whose lines all match RE. --strip-trailing-cr Strip trailing carriage return on input. -a --text Treat all files as text. -w NUM --width=NUM Output at most NUM (default 130) print columns. -l --left-column Output only the left column of common lines. -s --suppress-common-lines Do not output common lines. -t --expand-tabs Expand tabs to spaces in output. --tabsize=NUM Tab stops are every NUM (default 8) print columns. -d --minimal Try hard to find a smaller set of changes. -H --speed-large-files Assume large files and many scattered small changes. --diff-program=PROGRAM Use PROGRAM to compare files. -v --version Output version info. --help Output this help. If a FILE is `-', read standard input. Exit status is 0 if inputs are the same, 1 if different, 2 if trouble. AUTHOR
Written by Thomas Lord. REPORTING BUGS
Report bugs to <bug-gnu-utils@gnu.org>. COPYRIGHT
Copyright (C) 2007 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO
The full documentation for sdiff is maintained as a Texinfo manual. If the info and sdiff programs are properly installed at your site, the command info diff should give you access to the complete manual. diffutils 2.8.7-cvs January 2008 SDIFF(1)
All times are GMT -4. The time now is 07:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy