Parsing cvs diff output to get just the important information - linux

I have taken the cvs diff of two tags in a file output.diff. Now I need to parse that output.diff to get just the changes in spec file. The changes include added, deleted and modified packages. Also if a Patch (in any package) is added, deleted or modified and any version up of the package. Rest all the info of the diff output ( the lines added, line numbers and others) is not needed at all.
Please help. I am not getting through. It will be appreciated if bash script is suggested.

A portion of the file output.diff is under :
Index: dist/pkg/libcurl/arm-target-dev-libcurl.spec
===================================================================
RCS file: /usr/tmp/dist/pkg/libcurl/arm-target-dev-libcurl.spec,v
retrieving revision 1.49.2.5
retrieving revision 1.49.2.7
diff -r1.49.2.5 -r1.49.2.7
6c6
< Release: 08010005
Release: 08010006
11a12
Patch4: curl-7.21.7-rfc2616.patch
43a45
%patch4 -p1
115a118,120
Sat Dec 07 2012
-Added curl-7.21.7-rfs2616.patch
=======================================================================
I want just the name of the spec file and name of the Patch Added, deleted or modified.
Also the last to lines ( change log )
Example as per the above file portion :
libcurl.spec
Patch4: curl-7.21.7-rfc2616.patch
Sat Dec 07 2012
-Added curl-7.21.7-rfs2616.patch

Related

diff showing only the diff color without change code

I have changed line of a sql file file. But the diff only shows the diff colour without any change code.
the line is: #enabled=0, before the change we had 1 instead of 0.
without the gitattribute
*.sql text diff
I get the error message that file suppressed by a .gitattributes entry or the file's encoding is unsupported.
[this is the link of the image of my git diff] (https://i.stack.imgur.com/bgMvv.png)
You need to check your git status (assuming the #enabled=0 was done on your workstation)
Check if:
the file is indeed Test/Scripts/ScriptsIgnoredOnImport.sql
there is any local commit which would not have been pushed yet.
The file on GitHub can also tell you more, by typing b (which triggers the file "blame" view on GitHub).
As shown here, you can then "View blame prior to this change" and see if your #enabled= was visible then.
As noted by torek, you could have a difference in encoding as well.
As I mentioned in "How do I determine file encoding?", you can (even in a simple CMD on Windows), check the encoding of your current file with:
git show :your/file.sql | file -
# compare it with the previous version
git show #~your/file.sql | file -

How to preserve timestamp of original file post zip compression?

I have a lot of files on our servers which we compression with a filter that only the files older than x days will get compressed.
The zip command compresses the original, makes a filename.zip and removes the original.
This has a small problem that the timestamp changes since the compression job runs after x days.
So when we run files to remove older files (which are by now zip files), not all files get removed since the timestamp has changed from the original file to the compressed file.
I would like to add a condition where while zipping, i want the original timestamp of the file to be retained by the zip archive even though its running at a later date.
One way of doing this would be to
Get timestamp of each original file with a date command
Compress the original, remove the original
Use and insert the earlier stored timestamp to the new zip file using "touch"
I am looking for a simpler solution.
Some old file I had:
$ ls -l foo
-rw-r--r-- 1 james james 120 Sep 5 07:28 foo
Zip and redate:
$ zip foo.zip foo && touch -d "$(date -R -r foo)" foo.zip
Check it out:
$ ls -l foo.zip
-rw-r--r-- 1 james james 120 Sep 5 07:28 foo.zip
Remove the original:
$ rm -i foo
Yes you can unzip a file and preserve the old timestamp from the original time it was created. Steps to do this are as below:
Click on the filename.zip, properties
In the General tab, the security says "This file came from another computer and might be blocked to help protect this computer". Click on the Unblock check box and click OK
Extract the file and volla, the extracted file has the datatime stamp when the file was created/modified

How to get proper diff of merge commit in tig

if i got into tig main view, i get a nice graph of commits and merges. i'd prefer to just look at the merge commits to trunk but unlike with normal commits tig where tig shows the full diff with file contents, on merge commits it just shows a list of changed files in the diff view. How do i get tig to display the file contents diff on merge commits?
commit fb56223ec50cf659a308b3c9979c912881147689
Refs: [master], {origin/master}, {origin/HEAD}, juju-1.21-alpha1-229-gfb56223
Merge: 7e7c95d a017b5a
Author: Juju bot
AuthorDate: Mon Sep 22 01:22:03 2014 +0100
Commit: Juju bot
CommitDate: Mon Sep 22 01:22:03 2014 +0100
Merge pull request #803 from mjs/check-ssh-api-methods-are-allowed-during-upgrade
cmd/juju: ensure that API calls used by "juju ssh" are allowed during upgrades
We recently had a regression where an API call required by "juju ssh" wasn't being allowed by the API server while upgrades are in progress. "juju ssh" is one of the few commands that is supposed to work during upgrades.
The Client used by "juju ssh" is now forced into an interface and this is checked using reflection against what the API server will allow during upgrades. Effectively, the compiler helps to check that the required API methods will be allowed.
http://reviews.vapour.ws/r/64/diff/
apiserver/upgrading_root.go | 20 +++++++++++---------
cmd/juju/ssh.go | 15 +++++++++++----
cmd/juju/ssh_test.go | 24 ++++++++++++++++++++++++
3 files changed, 46 insertions(+), 13 deletions(-)
navigating to the individual files (j/k) in the view, says press 'Enter' to view file diff, but hitting enter gets "Failed to find file diff" err message. ideally i'd just be looking at the combined diff for the merge commit.
[update] i traced through tig with sysdig and it looks like its doing the following which on merge commits won't show the actual diff.
git show --encoding=UTF-8 --pretty=fuller --root --patch-with-stat --show-notes --no-color fb56223ec50cf659a308b3c9979c912881147689 --
i guess what i'm looking for on merge commits then is to parse the parents commits and then do something like the following
git diff 7e7c95d a017b5a
[update] so the diff actually isn't correct here as that diff would be between the two parents, and be more inclusive of changes then the merge itself, the best content rendering of the diff seems to be
git diff fb56223^ fb56223
Turns out this is pretty straightforward via external command integration.
I dropped this into ~/.tigrc:
bind diff 7 !git diff %(commit)^ %(commit)
and now just press 7 for the diff output i'm looking.
You have several options:
put this into your .tigrc
set diff-options = -m
you can set many options in ~/.tigrc, see also the manpage:
man tigrc
or start tig with the option -m
tig -m
Options to tig are passed to the underlying git command. More Info about this also in the manpage:
man tig

Applying a patch to files with spaces in names

Here's an output of diff -u "temp temp/docs 1.txt" "temp temp/docs 2.txt":
--- temp temp/docs 1.txt Mon Apr 7 16:15:08 2014
+++ temp temp/docs 2.txt Mon Apr 7 16:18:45 2014
## -2,6 +2,6 ##
22
333
4444
-555555
+55555
666666
7777777
However, feeding this diff to patch -u fails with following message:
can't find file to patch at input line 3
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|--- temp temp/docs 1.txt Mon Apr 7 16:15:08 2014
|+++ temp temp/docs 2.txt Mon Apr 7 16:18:45 2014
--------------------------
Apparently, the spaces are the problem; is there a way to make patch to work on files with spaces in names?
No, GNU patch doesn't support this. Here's the official statement: http://www.gnu.org/software/diffutils/manual/html_node/Unusual-File-Names.html#Unusual%20File%20Names
Gnu patch 2.6.1 (linux) seems to obey at least 1 space (not tried with more) if the filename is separated from the date with tab.
YYMV
I encountered the same problem when trying to establish conventions how to do manual version control with diff and patch.
I found out that GNU "diff" creates quoted path names in the patch headers if they contain spaces, while BusyBox "diff" doesn't.
Neither GNU nor BusyBox "patch" accepts quoted path names.
If the problem is just embedded spaces within filenames, it can therefore be avoided by using "busybox patch" rather than GNU "patch".
Another solution is to postprocess the output of GNU "diff" before feeding it into "patch":
sed 's,^\([-+]\{3\} \)"\([^"]*\)",\1\2,' $PATCHFILE | patch -p1
This works whether $PATCHFILE was created with GNU or busybox diff, but will only work with unified diff format.
Unfortunately, it turns out that leading or trailing spaces in filenames cannot be preserved with this method, as "patch" will skip them when parsing the path names from the patch instructions.
The approach will neither work if the filename starts with a literal double quote - but then, who uses such file names?
Most of the time, however, the above approach works just fine.
Finally a note of other approaches I have also tried but which did not work:
First I tried to replace the quotation of the whole path names by individually quoted path name components. This failed because "patch" does not use double quotes as meta-characters at all. It considers them to be normal literal characters.
Then I tried to replace all spaces by "\040" like CVS does - but "patch" does not seem to accept octal-escapes either, and this failed too.

Send previous day file to server in unix

I'm devloping a shell script to scp a.txt to different servers(box1 and box2) and script is running in boxmain server. Below are the requirements,
my script will connect to db2 database and generate a.txt file in boxmain
a.txt will be scp'ed to box1 once the file is generated
The file generated in boxmain(a.txt) will be scp'ed to box2 on the next day, i.e. It will be an SCP of the previous day's boxmain file
Note : box1,box2,boxmain are servers
i tried the below, able to finish first 2 tasks but stuck in 3rd. Please suggest how to achieve the third point. Thanks in advance.
db2 -tvf query.sql #creates a.txt
scp a.txt user#box1:/root/a.txt
now=$(date +"%m/%d/%Y")
cp a.txt a_$now.txt
my os version is AIX test 1 6
There is a slight problem with your question definition: using '/' in the name of your source filename will make it interpreted as not just a filename but a path containing directories as well because '/' is the directory separator. It might be a good idea to use now=$(date +"%m-%d-%Y") instead of now=$(date +"%m/%d/%Y").
But to answer your actual problem which I think boils down to this: how to get date(1) to output a date from yesterday on AIX?
The answer was found from The UNIX and Linux Forums: just set the environment variable describing your timezone to have +24 in it and you'll get yesterdays date from output of date.
For example:
user#foo ~]# date
Mon Nov 4 09:40:34 EET 2013
user#foor ~]# TZ=EST+24 date
Sun Nov 3 07:40:36 EST 2013
Applying this to your problem, just set an appropriate value for TZ when you run now=$(date +"%m/%d/%Y") ie. use now=$(TZ=ZONE+24 date +"%m-%d-%Y") (note the corrections on the path separator and replace ZONE with your own timezone).

Resources