loop and check


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting loop and check
# 1  
Old 10-22-2008
loop and check

Hi,

We are doing a process manually and i am trying to automate it.

This is the process.

We have a set of files in the directory /temp/d1. the number of files are dynamic.

For ex: if i have 5 files i want to compare the chatacters 45-58 of the last line of the first file with the same characters of the last line of the second file and so on until 5 files. We can ignore the first line of the first file and the last line of the last file.

I started doing it and am stuck, because the file numbers are dynamic.

for file_name in `ls ${INPUT_FILE_NAME}_*`;
do
${file_name}_h = `echo head -1 file_name|cut -c 45-58`;
${file_name}_t = `echo head -1 file_name|cut -c 45-58`;
done


can anyone please help.
# 2  
Old 10-22-2008
sorry there was a mistake:-

it should be:-

if i have 5 files i want to compare the chatacters 45-58 of the last line of the first file with the same characters of the first line of the second file and so on until 5 files. We can ignore the first line of the first file and the last line of the last file.
# 3  
Old 10-22-2008
below script check all the files like *.t in current directory, and then recurisly check the first line of file and last line of another file to check the matching result. May useful for you.

Code:
check() {
  a=`cat $1 | head -1`
  b=`cat $2 | tail -1`
  echo $a"  "$b
  if [ "$a" = "$b" ]
  then
     echo $1" --match-- "$2
  else
     echo $1" --mismatch-- "$2
  fi
}
for i in `ls *.t`
do
  for j in `ls *.t`
  do
    if [ $i != $j ]
    then
       check $i $j
    fi
  done
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check two condition in while loop

Hi, I Have to check two condition in while loop every 2 minutes. while loop is accompanied with number of times it will check.Please help in putting the two condition in while loop as appropriate. z= input value, A=1 while do 1.check the file output,if the file output is N then keep on... (2 Replies)
Discussion started by: netdbaind
2 Replies

2. Shell Programming and Scripting

While Loop to Check for Integer

Hello All, In ksh I am trying to ensure that user inputs are integers otherwise redisplay prompt with the following code; a=0 b=0 c=0 read b?"Please enter a number: " read c?"Please enter another number: " while ] && ]; do read b?"Not a number. Please enter a number: " read c?"Not... (4 Replies)
Discussion started by: techieg
4 Replies

3. Shell Programming and Scripting

IF loop to check the time modified

Hi Frnds, i have a folder test in which files generated daily how to chek the files that are modified on that day as a condition for ex, if then echo "i have got something to do with the file" else echo" sorry" fi i will have more than 3 to 4 files that are modified today. and if... (5 Replies)
Discussion started by: mahesh300182
5 Replies

4. UNIX for Dummies Questions & Answers

For loop to check the files availability

Hi, I need a help with my script. Below is my script. What I am doing here is finding the date of the file which I need to process and then finding the list of file names. Based on the list of file names, check has to be done to see if all the files are there and log the details to a error... (3 Replies)
Discussion started by: Vijay81
3 Replies

5. Shell Programming and Scripting

Check condition inside the loop

Hi, I am in trouble. I can get inside my condition test inside a loop : I am in ksh (solaris) while read file do <commande to retrieve file> >> ${LOG_RETRIEVE_FILE.log} msg_err=$(cat ${LOG_RETRIEVE_FILE.log} | grep "error retrieve") if ; then <sendmail> exit 1 fi done I tried... (6 Replies)
Discussion started by: Aswex
6 Replies

6. Shell Programming and Scripting

WHILE LOOP CONDITION CHECK

Hello I want to compare values of two variables as CHECK condition in a while loop. eg: var1=0 var2=10 while do echo " $var1 " var1=`expr $var1 + 1` done However this is giving error.How to do it in a proper manner? Thanks. (3 Replies)
Discussion started by: dashing201
3 Replies

7. Shell Programming and Scripting

Loop check

Hi Gurus I have a recquirement where my loop should work if i have more than 4 listed files in a particular directory. Like the loop in while should continue checking if the directory has more than 4 files and should exit after there are 4 or more files ; if not more than 4 files it should... (5 Replies)
Discussion started by: r_t_1601
5 Replies

8. Shell Programming and Scripting

Check for statup process in loop?

I've written a script to check for Oracle's listener, eventman and pmon processes however there are several databases that startup which can take several minutes. I'd like to add code to my current script that greps for the process “startup” and whether its condition is true or false. If the... (1 Reply)
Discussion started by: dataciph3r
1 Replies

9. Shell Programming and Scripting

Loop to check for file up to 3 times

Please forgive this I think rather basic question. I have been away from UNIX for a very long time and am in need of some help. I need to be able to check for the existance of a specific file name say 'file.dat' in a particular location If the file exists then run a second process (at... (2 Replies)
Discussion started by: JohnCrump
2 Replies

10. Shell Programming and Scripting

looking for help with a dd loop check script

Hi Can anyone please help with the following script I need - .ksh preferably? I have external disks attached to a system that I have to label and then run the dd command on all external disk found. I have kicked off the dd command as follows manually to see what its output is like first... (1 Reply)
Discussion started by: angusyoung
1 Replies
Login or Register to Ask a Question