Compare two string and get "exact" difference only
Hi all;
Pretty green to perl programming; been searching high and low for a perl (preferably) or unix script that will compare 2 CSV strings in the same file that are separated buy the "|" character (so basically they're side by side) and give the results of ONLY the exact change; note that 19 is not a line number it's just a numeric field. If it helps; we can assume that both CSV strings have fields so we can call them:
rule, client, location, script, destination, enabled, search, compress
Also; rule can never be altered\changed only fields 2 to 8 can be modified.
So with all that here's an exmple; if I have a file (call it file1) with this content:
Output I am looking for (to be written to file2):
Notes: notice on the SUMMARY that even though there were 2 records changed for client gjv that it only appears once in the line "Rule was changed for 2 clients:" but it is accouhted for in the line "Total number of rules changes:"
Thanks
G
Last edited by jim mcnamara; 02-09-2012 at 01:15 PM..
Reason: added code tags; please use them
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 2,288
Thanks Given: 430
Thanked 480 Times in 395 Posts
Hi.
I tend to use whatever is "standard" or available on systems before I start coding a custom solution. So here is an example using utility dwdiff. The output is not in the format you desired, but it was quick to put together. The key part is the dwdiff and the slight reformatting with sed:
producing:
The square brackets mark deletions, curly braces insertions. Both can be changed.
I'm on Ubuntu 14.04 and I manually updated my coreutils so that "tee" is now on version 8.27
I was running a script using bash where there is some write to pipe error at some point causing the tee command to exit abruptly while the script continues to run. The newer version of tee seems to prevent... (2 Replies)
Dear Ladies & Gents,
I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out:
for filename in $(find /var/log/test... (2 Replies)
Hello.
Following recommendations for one of my threads, this is working perfectly :
#!/bin/bash
CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" )
Now I need a grep success for some thing like :
#!/bin/bash
CNT=$( grep -c -e "some text_1... (4 Replies)
I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here.
I have following script (called out_to_streams.csh):
#!/bin/tcsh -f
echo Redirected to STDOUT > /dev/stdout
echo Redirected to... (2 Replies)
logs:
"/home/abc/public_html/index.php"
"/home/abc/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
"/home/xyz/public_html/index.php"
how to use "cut" or "awk" or "sed" to get the following result:
abc
abc
xyz
xyz
xyz (8 Replies)
Hello everyone
Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried
sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
I have a file that contains the 2 following lines (from /proc/mounts)
/dev/sdc1 /mnt/backup2 xfs rw,relatime,attr2,noquota 0 0
/dev/sdb1 /mnt/backup xfs rw,relatime,attr2,noquota 0 0
I need to match the string in the second column exactly so that only one result is returned, e.g.
> grep... (2 Replies)
Hi,
could someone pls enlighten me on the difference between the "root" package and "usr" package?
Like in this example:
pkginfo -l SUNWGtku | grep -i desc
DESC: GTK - The GIMP Toolkit (Usr)
and
pkginfo -l SUNWGtkr | grep -i desc
DESC: GTK - The GIMP Toolkit (Root)... (6 Replies)
I have many Gaussian output files, which contain a string start from "HF=" but follws the different values. I'm trying to get this exact string from these txt files.
example 1,
2.524075,-0.563322,-1.285286\H,0,-2.544438,-0.678834,1.199166\H,0,2.18
... (7 Replies)