Compare two files and lines which are the same just delete it
I am having a two files and different days, and this is example:
file1: 06.09.2017.
file2: 07.09.2017.
So what I want is that file2 with today's date contains only 1234, so where is a problem you would ask?
Problem is here that I put these commands into routers,. and error occurred with message that interface already exist, and no other commands are pasted into router.
Solution that I think is to compare two files, one yesterday and one for today, and compare it, if lines are the same DELETE IT FROM TODAY and leave only what is different.
Last edited by rbatte1; 09-07-2017 at 04:56 AM..
Reason: Added CODE tags, corrected spelling etc.
compare two files, one yesterday and one for today, and compare it, if lines are the same DELETE IT FROM TODAY and leave only what is different.
If your file contents are "well-behaved", that is: contain no regexp metacharacters (somehow i don't that i have been shown the real content with "1234"), you can use grep -vf file1 file2 to filter all lines out of file2 which are also in file1.
i manage to succed with this command
and it give me the line which are only changed, but there is a some another problem...
the line which is changed is inside a interface setup.
And only THAT command when put to router does nothing, it must first go into interface
example:
so if I change only ssid, my awk command give me output
and that command i cant paste into router, i must and
So i cant figure out how to do it.
I want to give a backup to another rotuer and if something is changed on the first one to be changed to the second, and my script does it good, but when change something like this, nothing happend, it error at first command with interface with error that interface already exist...
And only THAT command when put to router does nothing, it must first go into interface
example:
so if I change only ssid, my awk command give me output
and that command i cant paste into router, i must and
Please understand: this type of things is context-aware: your "set ..." means different things if it is prefaced by "/interface wireless" (then it is a command part) or not (then it is something undecipherable by tre router).
To make a program understand (and hence take into account) such differences you need to parse the input. And parsing - as a recursive process - cannot be done by regexps. Therefore your whole problem description:
Quote:
So what I want is that file2 with today's date contains only 1234
is basically meaningless. In fact you need a parser which identifies not the changed lines but the changed configuration commands leading to a different setup. For this you need a language interpreter (of which the parser is one part, the lexical analyser is the other) for the routers configuration language.
I hate to break it to you but writing a parser is too big a project to do it here in a post. There are a lot of articles in the internet, though, which explain how to do it.
Hello, my first thread here.
I've been searching and fiddling around for about a week and I cannot find a solution.:confused:
I have been converting all of my home videos to HEVC and sometimes the files end up smaller and sometimes they don't. I am currently comparing all the video files... (5 Replies)
I have two files
I need to compare these two files and take the lines that are common in both the files and consider the line present in second file for my further processing
I have used "Awk" along with "FNR and NR" but that is not working
gawk -F= '
> FNR==NR {a=$1; next};
> ... (2 Replies)
I have 2 files with exactly the same information (with header and separated by ";") and what I would like to do is print (for both files!) the columns that are different and also print the "key" column that is equal in the 2 files For example, if
File1:
key1;aaa;bbb;ccc
key2;ddd;eee;fff... (4 Replies)
Hello,
I have a group of text files with many lines in each file.
I need to delete all the lines in each and only leave 2 lines in each file. (3 Replies)
Hi, i have a problem,
I have three files, file_1, File_2 file_3 and I need to compare the data with file_3 file_1, data that are equal to file_3 file_1 should be deleted, file_1 receive data and file_2 file_3.
Ex:
file_1
374905,2001, Selmar Santos, Técnico de Sistemas, U$3.000,00
789502,... (3 Replies)
I do not know much about shell scripting so I am at a loss here. If someone can help me, that would be great!
I have two directories
/dir1
/dir2
I need to delete all files from /dir1 and that does not have a correspondent file in /dir2. It should NOT check file suffixes in /dir2 . Why?... (20 Replies)
I have a unique situation here which looks easier at first but I am not able to solve it.
# SSort UNIX 10/14/2005 10/13/2010 "tox" "9000/800" 16 * * * V849-6-1
# SSort UNIX 11/31/1996 11/02/2010 "tox" "9000/800" 16 * * * W237-S-2
I have a text file with two or multiple values like this and... (1 Reply)
Hi
I want to delete first five and last five lines in text files without opening the file and also i want to keep the same file name for all the files.
Thanks in advance!!!
Ragav (10 Replies)
Hi there,
I have written a script called "compare" (see below) to make comparison between 2 files namely test_put.log and Output_A0.log
#!/bin/ksh
while read file
do
found="no"
while read line
do
echo $line | grep $file > /dev/null
if
then
echo $file found
found="yes"
break
fi... (3 Replies)