Process diff command output in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process diff command output in a shell script
# 1  
Old 12-11-2009
Process diff command output in a shell script

Code:
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

Code:
ss=$(diff -yta file1 file2)

it appears as
Code:
#!/usr/abc/b/bin/perl5.6 | #!/usr/abc/b/bin/perl5.8

As you may notice, all the spaces are removed. What I want to do is process the exact output of diff command line by line.

Appreciate any pointers on this.

Thanks in advance.
# 2  
Old 12-11-2009
The "problem" is the way parameter expansion is done. Example:
Code:
$ cat test.sh
#!/usr/bin/ksh

VAR='Test  with  double  size  whitespace  !'

echo $VAR
echo "$VAR"
$ ksh test.sh
Test with double size whitespace !
Test  with  double  size  whitespace  !

Spot the difference? In the first example, echo is passed 6 parameters (split on the whitespaces), and by default it outputs them using one whitespace as separator. In the second example, the variable is passed as one parameter, whitespaces and all.
# 3  
Old 12-11-2009
Fantastic! Thanks pludi.

The other question I have is how can I show entire line content in the diff result? I tried with diff -yta -W 300, however, the result is distorted.

Any idea?

Thanks.
# 4  
Old 12-11-2009
What do you mean by "distorted"? Can you give an example?
# 5  
Old 12-11-2009
Code:
diff -yta -W 300 file1 file2

#!/usr/abc/b/bin/perl5.6                                                                                                                         |  #!/usr/abc/b/bin/perl5.8
###########################################################################                                                                             ###########################################################################

Above result shows output from file1 followed by file2. As you may notice, diff tries to set the result in 300 characters and that's why the output doesn't set on one line.

Does it help to understand the scenario?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass ls command output to diff

Hi , Can some one help me how to pass ls command output to diff command ex : - ls *.xml will return files which have time stamps abc-<time-stamp>.xml xyz-<time-stamp>.xml diff abc-<time-stamp>.xml xyz-<time-stamp>.xml >> newfile.txt we need to... (9 Replies)
Discussion started by: techie_09
9 Replies

2. Shell Programming and Scripting

How to pipe command output to shell script?

Hi Team, Need a help on how to pipe a command out put to a shell script. My shell script looks like below. cat shell_script #!/usr/bin/ksh input =$@ echo " we are inside the shell script" echo " here are the input parameters" .......................... .................. ... (11 Replies)
Discussion started by: gvkumar25
11 Replies

3. Shell Programming and Scripting

Shell script to replace output of command

Hi I would like to write a shell script which replace particular text in output of a shell command. For example : If I execute pwd (if dir is /users/master/) it should display as - /users/Master_directory/. Also, for generalising the script I would like to receive parameters when I run the... (3 Replies)
Discussion started by: ratneshnagori
3 Replies

4. Shell Programming and Scripting

shell script to format command output

Hello team, I am running below command which is giving following output. bash-3.00$ ps -eo pid,pcpu,args | sort +1n | grep -i java 12 0.0 grep -i java 8804 0.0 /opt/app/ccr/home/ccr/WebSphere/AppServer/java/bin/sparcv9/java -XX:+UnlockDiag 9241 0.0... (7 Replies)
Discussion started by: coolguyamy
7 Replies

5. Shell Programming and Scripting

Need help with shell script - output of top command

I have written shell script to send file as an attachemt of email and output of "top -o res" command as email body. it works fine if i execute manually from prompt but it does not send "top -o res" command output in email body when it is executed via crontab. Any suggestions. My script is below:... (5 Replies)
Discussion started by: needyourhelp10
5 Replies

6. Shell Programming and Scripting

Evaluating command output (shell script )

Hello, in a script i would like to evaluate a command output with a grep, for example, to know if the parameter defined by the user is in the output. Something like: the_command | grep $1 Please, how is the way to evalulate in this a script, like if echo "incorrect parameter, not in... (2 Replies)
Discussion started by: aristegui
2 Replies

7. Shell Programming and Scripting

parsing output from a diff command...

hi, i have a script which pipes the output of a diff -rq command into a separate file/ it would read something like this: Files mod1/lala/xml/test1.txt and mod2/lala/xml/test1.txt differ Only in mod2/lala/xml: test2.txt What i need to do is to parse this file so i end up with just a... (5 Replies)
Discussion started by: kam
5 Replies

8. Shell Programming and Scripting

reading command output from shell script

Hi List, How to read the output of a command executed from a script. For ex. sample_scritp.sh ------------- useradd testuser1 password testuser1 .... ..... -------------- This prompts for "password", and "confirm password", for which i need to give the values from script. Can... (4 Replies)
Discussion started by: sri b
4 Replies

9. Shell Programming and Scripting

Capturing shell script command output

I am trying to check to see if a file exists on a ftp server, well, I know that cant be done, atleast directly, So I came up with this small script ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD cd public_html/crap dir $FILE quit END_SCRIPT Where the $ variable... (2 Replies)
Discussion started by: designflaw
2 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question