My first script of day, it looks easy, but...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My first script of day, it looks easy, but...
# 1  
Old 11-27-2008
My first script of day, it looks easy, but...

I've began my journey at 7:50, and at this time i've lost 40 minutes in this easy but SmilieSmilie-script.
Someone can help me ? I want to see the differences beetween all xml files in two directories (they must be equals), and this is my script:

Code:
#!/bin/bash

dir1="261108"
dir2="261108_vista"

for i in `ls -las ./$dir1/*.xml | awk '{print $10}'`
do
  echo "For $i  file  we have differences: "
  grupo1=${dir1}/${i}
  grupo2=${dir2}/${i}
  diff ${grupo1} ${grupo2}
done

This is one-loop output:

Code:
For ./261108/Clustering_config.fdp1.xml  file  we have differences: 
diff: 261108/./261108/Clustering_config.fdp1.xml: No such file or directory
diff: 261108_vista/./261108/Clustering_config.fdp1.xml: No such file or directory

Why it executes diff two times?? and why $grupo1 and $grupo2 are bad-formed ??

Thx all
# 2  
Old 11-27-2008
Remove the coloured part:

Code:
#!/bin/bash

dir1="261108"
dir2="261108_vista"

for i in `ls -las ./$dir1/*.xml | awk '{print $10}'`
do
  echo "For $i  file  we have differences: "
  grupo1=${dir1}/${i}
  grupo2=${dir2}/${i}
  diff ${grupo1} ${grupo2}
done

Regards
# 3  
Old 11-27-2008
Hi all,
I have another suggestion, a simplification:

Code:
#!/bin/bash
cd 261108
for i in *.xml; do
diff $i ../261108_vista/$i &> /dev/null || echo file $i differs
done
cd ..

Assuming that there are no space in filenames. I am just using constants to make it a bit clearer.

/Lakris
# 4  
Old 11-27-2008
for-loops considered harmful

Once again i would like to offer my sentiment that for-loops are a dangerous device to cycle through filelists:

https://www.unix.com/unix-dummies-que...#post302260300

I hope this helps.

bakunin
# 5  
Old 11-27-2008
"You know, I learned something today..."

actually, I knew but it's always good with a reminder Smilie
Here's a spiced up version inspired by the link:

Code:
#!/bin/bash
cd 261108
ls -1 *.xml | while read i ; do
diff "$i" "../261108_vista/$i" &> /dev/null || echo file $i differs
done
cd ..


/Lakris

Last edited by Lakris; 11-27-2008 at 03:18 PM..
# 6  
Old 12-02-2008
Thx all, me too hate for-loops
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Easy script

Write a script, which of the directory including sources of kernel, choose files with sources in C (files with .c extension), including in name "io" with dirvers (located in random subdirectory drivers) and place their content in file FILE. (to 20 lines). Could someone help me with this task?... (1 Reply)
Discussion started by: Czabi
1 Replies

2. Shell Programming and Scripting

Script to check if last modified day is previous day

Hi, I would like to write a script that checks if a file ('counter') was modified the previous day, if so erase its contents and write 00000000 into it. For e.g. if the file 'counter' was last modified at 11.30pm on 24th May and the script runs at 12.15am of 25th May, it should erase it's... (1 Reply)
Discussion started by: hegdepras
1 Replies

3. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

4. Shell Programming and Scripting

Easy Checkup Script

Hi, I am planning the following to do. On my linux system I've got different users in the /home/ directory. These users have file limitations. So every user below the /home/ directory should get a text file in a seperate folder /home/$user/files/ which tells him how many files he is already... (2 Replies)
Discussion started by: crusher
2 Replies

5. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies

6. UNIX for Dummies Questions & Answers

Help with an 'easy' script

Hello guys, Forgive me if I duplicate the post but i think i make a mistake choosing the correct forum. I need some help to solve a little problem, I have a big file with almost 100.000 lines of data, here is an example of line: 100099C01101C00000000059399489283CREMOVISTAR_TX ... (3 Replies)
Discussion started by: lestat_ecuador
3 Replies

7. Shell Programming and Scripting

Help with an 'easy' script

Hello guys, I need some help to solve a little problem that I have here: I have a big file with almost 100.000 lines of data, here is an example of line: 100099C01101C00000000059399489283CREMOVISTAR_TX 010001C00000000000099069799MOVISTAR_Tx ... (7 Replies)
Discussion started by: lestat_ecuador
7 Replies

8. Shell Programming and Scripting

easy script

a script, cheer that prints its parameter as shown in the example below. eg: $ cheer U N I X Give me a U! U! Give me a N! N! Give me a I! I! Give me a X! X! #!/bin/sh for letter do echo "Give me a $letter!";echo "$letter!" done this is the code i used for the above script (2 Replies)
Discussion started by: problems
2 Replies

9. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies

10. UNIX for Dummies Questions & Answers

Easy script

Hi there, Could you please help me with that ? I want to grep a specific string in an .xml file and then rename the file according to the string I found. How can I do that for many files. Because all the files have similar names but different time stamps I want to name them so it's easy to... (8 Replies)
Discussion started by: guest100
8 Replies
Login or Register to Ask a Question