shell scripting my own diff command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers shell scripting my own diff command
# 1  
Old 12-10-2003
shell scripting my own diff command

Hi I would like to run the diff command and recieve a little different output. I am on a linux machine. I am pretty new to shell scripting. So far my idea has shaped up to this, unworking, script. I would like file1: and file2: instead of the usual > or < output you recieve,

diff | sed -e s/^<*/file1:/g s/^>*/file2:/g d/---/g

Can anyone help me shape this into a working script?
# 2  
Old 12-10-2003
Give this a try: Smilie

diff file1 file2 | sed -e 's/^</file1:/g' -e 's/^>/file2:/g'
# 3  
Old 12-10-2003
I am writing this to use as a shell script, that I can run on multiple files by typing just: mydiff firstfile secondfile

I have been working and have this code:

diff $1 $2 | sed -e 's/^<*/file1:/g' -e 's/^>*/file2:/g'


I type: mydiff firstfile secondfile
It is running the diff but output comes out like this:

file2:file1:>
file2:file1:>
file2:file1:>
file2:file1:>

Thanks for the reply
# 4  
Old 12-10-2003
oombera's reply works all you have to do is replace diff file1 file2 w/ diff $1 $2 and it works from a shell script.
# 5  
Old 12-11-2003
Thanks for the replies I had it working in my second post, I was just confused by the output. It is working smoothly now. Thanks eveyone
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in shell Scripting to display a output from a command

Please find my below requirement and see if you can help me on this. I am looking for a shell script which can provide me the below output. Manuall steps which i am doing now 1) First I source the File $ . ./WC_env.sh 2) Execute the command $ /app/oracle/product/mos/bin/mosotl -url... (2 Replies)
Discussion started by: sudheshpn@gmail
2 Replies

2. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

Hi , Please excuse me for opening a new thread i am unable to find out the syntax error in my if else condition inside for loop in awk command , my actual aim is to print formatted html td tag when if condition (True) having string as "failed", could anyone please advise what is the right... (2 Replies)
Discussion started by: karthikram
2 Replies

3. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

4. Shell Programming and Scripting

PERL Scripting: Diff 2 files and save output to file3

Hi, I need to create a script to compare 2 files and store the output in a 3rd file. This is how I do manually, but since I need to do this for about 150 files every week, I am trying to automate it using perl. diff -u file1 file2 > file3.patch For my script, - I have 2 files... (4 Replies)
Discussion started by: script2010
4 Replies

5. Shell Programming and Scripting

Process diff command output in a shell script

diff -yta file1 file2 #!/usr/abc/b/bin/perl5.6 | #!/usr/abc/b/bin/perl5.8 Notable thing about above line is "|" appears at 62nd position. When the same line is assigned in a variable in a ksh script, using ss=$(diff -yta file1 file2) it appears as ... (4 Replies)
Discussion started by: bhaliyajalpesh
4 Replies

6. Shell Programming and Scripting

shell scripting best practices - trap command

I know there is a command called trap which can be used to capture the signals from a shell script and redirect the control to a required function (such as a cleanup). My question is - Those of you who have written lot of shell scripts - do you always write a set of trap commands to capture... (4 Replies)
Discussion started by: sagar_evc
4 Replies

7. Shell Programming and Scripting

How to compare a command line parameter with -- in shell scripting

Hi, I need to check if a parameter provided at the command line is equal to --.How can i do that ? Please help me. Thanks and Regards, Padmini (4 Replies)
Discussion started by: padmisri
4 Replies

8. Shell Programming and Scripting

recommend book for unix command/ shell scripting

Hi, i wish to learn unix commands and shell scripting. platform is solaris. but i am focused more on handy unix commands than system administration. which books do you recommend? (1 Reply)
Discussion started by: nurulamin862
1 Replies

9. Shell Programming and Scripting

Need help with Scripting diff command

Here is where I am at so far..... ------------------------- #!/bin/bash echo "Enter the output file name" read output_file echo "Enter the Orginal file Name" read write_file d= ' diff $write_file $output_file ' if $d = 1 ;then echo "files are not identical" else echo "they... (2 Replies)
Discussion started by: tlfletcher05
2 Replies

10. Shell Programming and Scripting

difference between AIX shell scripting and Unix shell scripting.

please give the difference between AIX shell scripting and Unix shell scripting. (2 Replies)
Discussion started by: haroonec
2 Replies
Login or Register to Ask a Question