I am very much new to shell script and found a way about how to compare files using shell script while using md5sum
.
I want to compare Options_old
and Options_new
files in shell script and identify the new Ticker field value added in the new file. For this new ticker field value I want to create CSV file.
For example if we compare Options_old
and Options_new
files and check the Options_new
file there is new ticker field value 510051 2 C2.50
and 510052 2 P2.50
added and I want to create and print this value in CSV file.
Options_new.out.gz file
START-OF-FILE
PROGRAMNAME=getdata
DATEFORMAT=yyyymmdd
START-OF-FIELDS
TICKER
EXCH_CODE
END-OF-FIELDS
TIMESTARTED=Wed Feb 12 19:30:38 JST 2020
START-OF-DATA
510051 CH 02/26/20 C2.5 Equity|0|75|510051 2 C2.50|CH
510052 CH 02/26/20 P2.5 Equity|0|75|510052 2 P2.50|CH
510050 CH 02/26/20 C2.55 Equity|0|75|510050 2 C2.55|CH
510050 CH 02/26/20 P2.55 Equity|0|75|510050 2 P2.55|CH
END-OF-DATA
DATARECORDS=1140
TIMEFINISHED=Wed Feb 12 19:32:50 JST 2020
END-OF-FILE
Options_old.out.gz file
START-OF-FILE
PROGRAMNAME=getdata
DATEFORMAT=yyyymmdd
START-OF-FIELDS
TICKER
EXCH_CODE
END-OF-FIELDS
TIMESTARTED=Wed Feb 12 19:30:38 JST 2020
START-OF-DATA
510050 CH 02/26/20 C2.5 Equity|0|75|510050 2 C2.50|CH
510050 CH 02/26/20 P2.5 Equity|0|75|510050 2 P2.50|CH
510050 CH 02/26/20 C2.55 Equity|0|75|510050 2 C2.55|CH
510050 CH 02/26/20 P2.55 Equity|0|75|510050 2 P2.55|CH
END-OF-DATA
DATARECORDS=1140
TIMEFINISHED=Wed Feb 12 19:32:50 JST 2020
END-OF-FILE
I have started the code but not understood further how to compare the particular field and then generate csv file:
#!/bin/sh
OLD_PATH="/opt/old"
NEW_PATH="/opt/new"
FILES="${FILES} Options_new.out.gz Options_old.out.gz"
for FILE in `echo ${FILES}`
do
MD5SUM_NEW=`md5sum ${OLD_PATH}/${FILE} | awk '{print $1}'`
MD5SUM_OLD=`md5sum ${NEW_PATH}/${FILE} | awk '{print $1}'`
if [ "${MD5SUM_NEW}" != "${MD5SUM_OLD}" ]; then
echo "Found new Version of ${FILE}"
#currently i am comparing the data from the whole file but i want to compare the data only for the Ticker value in the both files
#here create new csv file with the new ticker value found in Options_new.out.gz file
fi
exit ${EXIT}