|
Simple Unix Program - need help (Non technical Person )
Hi everyone,
I have a requirement to compare two given files using Unix coding. can some one help me out ? The following is the requirement 1.There are 2 folders /tmp/mks/input and /tmp/mks/output 2.with the following Input and its corresponding output file R8509yzxs67gcz5cg9e6m9is.DAT and Cata9yzxs67gcz5cg9e6m9isRTGATA.DAT present in them 3. the first file is an Input file to the system and second file is an output from the system which are stored respectively at /tmp/mks/input and /tmp/mks/output 4. I now need to run a script and find if an input file is present in the outputfolder also (which will mean successful processing).(In real time there will be many files in both the folders that should be checked) 5.The relation between them can be got by the following method any input or output file will have the following string "9yzxs" which will be followed by 15 unique alphanumeric characters for the inbound and outbound. eg: we have 2 input files as R8509yzxs67gcz5cg9e6m9is.DAT & R8509yzxs97abc5cg9e6m9is.DAT then we will have outputs like Cata9yzxs67gcz5cg9e6m9isRTGATA.DAT and Cata9yzxs97abc5cg9e6m9isRTGATA.DAT now i need a script to display for which all input files an out put exists and for which it doesn't. PS: i will be very thankful if you can explain the Logic, as i can make some custom changes in near future and may not trouble others.
1 Answer
#!/bin/bash
INPUT=/tmp/mks/input
OUTPUT=/tmp/mks/output
## search for possible input files
cd $INPUT
for i in *9yzxs*.DAT
do
## create a possible output file - checking the 15 alphanumeric limit as well
OUT=$(echo $i | sed -ne "s/^R850\(9yzxs[a-zA-Z0-9]\{15\}\).DAT/Cata\1RTGATA.DAT/p")
## Ignore if the input didn't have the right number of chars
[ -n "$OUT" ] || continue
## We have a valid input now, so we can check if it has output as well
if [ -f $OUTPUT/$OUT ]
then
echo $INPUT/$i has output of $OUTPUT/$OUT
else
echo $INPUT/$i has no output
fi
done
Posted: xtremex 1 of 1 people found this answer helpful. Did you? Yes No Hi Xtremex,
Thanks for the Coding. Could you please explain thecodings in line 11 and 13 .. If you could spell out the Logic used there, it would be of great use to me. |
© Advanced Web Core. All rights reserved

