LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-02-2009, 04:04 PM   #1
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Rep: Reputation: 37
[bash] auto fix file from diff output


Hi guys,

I would like to create a little script that allows me to use the diff output and actually make the modifications on a file.

ex.


I am having some troubles with my kernel configuration, and somebody gave me a hint on how to solve it and i want to simply pass what he gave me to my .config...

this is what i have:

file1

Quote:
# SCSI device support
CONFIG_SCSI=y
CONFIG_SCSI_DMA=y
# CONFIG_SCSI_TGT is not set
# CONFIG_SCSI_NETLINK is not set
# CONFIG_SCSI_PROC_FS is not set
# SCSI support type (disk, tape, CD-ROM)
# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
# CONFIG_SCSI_MULTI_LUN is not set

+more stuff
file2
Quote:
# SCSI device support
CONFIG_SCSI=y
CONFIG_SCSI_DMA=y
# CONFIG_SCSI_TGT is not set
# CONFIG_SCSI_NETLINK is not set
CONFIG_SCSI_PROC_FS=y
# SCSI support type (disk, tape, CD-ROM)
# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
# CONFIG_SCSI_MULTI_LUN is not set

+more stuff

so i did this:

Code:
diff file1 file2 > diff
and i get the following:

Quote:
6c6
< # CONFIG_SCSI_PROC_FS is not set
---
> CONFIG_SCSI_PROC_FS=y
11,12c11,12
< CONFIG_SCSI_LOGGING=y
< CONFIG_SCSI_SCAN_ASYNC=y
I am not that good at bash yet so I would like some help on this one.

So basically what i want to do is create a little script that takes the diff file as a parameter and parses another file.

I was thinking about doing something like:

for each "<" remove that from the target file
and for each ">" add it to the target file.

I know that sed 's///' would substitute things but im not sure how to put all together.

Any ideas would be appreciated guys!

EDIT:

Im just reading about patch... i guess it will do.

Last edited by RaptorX; 08-02-2009 at 04:20 PM.
 
Old 08-02-2009, 04:44 PM   #2
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Original Poster
Rep: Reputation: 37
ok here is the problem:

the guy did

grep -i ata .config && grep -i scsi .config

and i did the same.

I have both outputs in to file1 and file2, and i did a diff on them.

now that diff will not work in .config since it has many other lines!
can somebody point me out in here?
how do i commit his changes to my kernel?
 
Old 08-02-2009, 05:04 PM   #3
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Code:
shell# diff -up file1 file2 | patch
Works for me


Sasha

NOTE: I'm not sure totally what you're trying to accomplish as far as the actual changes; but, doing my command there, diffs file1 against file2, then patches file1.

Hint: if you want to run `script file1 file2` then the script would resemble:

Code:
#!/bin/bash

# scriptname: script
/usr/bin/diff -up $1 $2 | /usr/bin/patch
and the /usr/bin/ is optional generally. It isn't necessary as the tools diff and patch will (should) be in the $PATH

Last edited by GrapefruiTgirl; 08-02-2009 at 05:15 PM. Reason: added script example.
 
1 members found this post helpful.
Old 08-02-2009, 06:17 PM   #4
RaptorX
Member
 
Registered: Jun 2009
Location: Emden, Germany
Distribution: Slackware 12.2, Slax 6.1
Posts: 254

Original Poster
Rep: Reputation: 37
well thats the problem, he did not send his whole .config file, just part of it.

he did:

Code:
grep -i ata .config > file2 && grep -i scsi .config >> file2
so I dont think I would be able to diff .config file2
because file2 is just part of .config and diff would tell me that i would have to delete 90% of the contents....

so what is the best way to go then?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH: How to Redirect Output to File, AND Still Have it on Screen edwin11 Linux - Software 25 07-02-2012 07:12 PM
[SOLVED] Bash script - how to use output from diff and find in context with cpio Mogget Programming 4 01-23-2009 11:38 AM
bash: unexpected end of file --fix BeacoN Linux - Newbie 1 11-10-2008 12:31 PM
bash command redirecting output to file freeindy Programming 10 11-08-2007 06:48 AM
Bash output to file stryka Programming 6 12-20-2005 08:21 AM


All times are GMT -5. The time now is 09:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration