I have two files.
one file consists of process ID's:
ProcessID1
ProcessID2
ProcessID3
Second file consists of 3 records:
username1 ProcessID1 Date1 Time1 ProcessName1
username2 ProcessID2 Date2 Time2 ProcessName2
username3 ProcessID3 Date3 Time3 ProcessName3
I have to search the first file whether any of the process id's of second file are present or not
If process ID is not there in the first file corresponding to second file, then we will move that record to a new file, otherwise we will remove that record.
I have written a script for this.But it is not working.
script:
for file in second_file
do
cut -c 8-12 second_file>>dummy_file
if [ dummy_file == First_file ]
$file >>new_file
else
continue
done
can anybody help me in this?
Thanks in advance
ilan
July 27, 2009, 5:40am
2
To satisfy this condition you could do this..
grep -v -f file1 file2 > newfile
clx
July 27, 2009, 5:45am
3
you want to compare with respect to the whole file or the line?
I mean, where you want to compare the records? on the same line or anywhere in the file?
secondly.. please confirm about "move the records"
as per your code, It will just echoing the values in another file ( not deleting from the actual file).
i tried that command :
grep -v -f file1 file2
but it gave the error as
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .
can anybody help in this please
thanmks in advance
---------- Post updated at 05:10 AM ---------- Previous update was at 04:59 AM ----------
Hi
I want to compare the records on anywhere in the file.
It is just enough to echo the values in another file. it is not necessary to delete that file
thanks in advance
/usr/xpg4/bin/grep -f /tmp/pattern.txt /tmp/my_file.txt
while read record
do
a=`grep $record file2`
if [ "$a" == "" ]
then
echo $record >>newfile
fi
done<file1
$
$ cat file1
ProcessID1
ProcessID3
ProcessID5
$
$ cat file2
username1 ProcessID1 Date1 Time1 ProcessName1
username2 ProcessID2 Date2 Time2 ProcessName2
username3 ProcessID3 Date3 Time3 ProcessName3
username4 ProcessID4 Date4 Time4 ProcessName4
username5 ProcessID5 Date5 Time5 ProcessName5
username6 ProcessID6 Date6 Time6 ProcessName6
$
$ perl -ne 'BEGIN{open(F,"file1"); while(<F>){chomp; $x{$_}=1} close(F)}{split; print if !defined $x{$_[1]}}' file2
username2 ProcessID2 Date2 Time2 ProcessName2
username4 ProcessID4 Date4 Time4 ProcessName4
username6 ProcessID6 Date6 Time6 ProcessName6
$
$
tyler_durden