Minor changes to script

isNumeric()
{
numericExpression='^[0-9]+$'
if ! [[ $1 =~ $numericExpression ]]
then
echo 1;
else
echo 0;
fi
}

getColumnData()
{
echo `echo $1|cut -d "," -f1,2 --output-delimiter " "`
}

containsSegment()
{
if [[ $1 =~ "LSNCS808" ]] || [[ $1 =~ "LSNCS097" ]] || [[ $1 =~ "LSNCS148" ]]
then
echo 0;
else
echo 1;
fi
}
FOLDER=/omnicron-space/Lifesys/Segdataconv/csv_files
EXTENSION=csv
SEGMENT_FILE=${FOLDER}/$1_SEGMENT.${EXTENSION}
NON_SEGMENT_FILE=${FOLDER}/$1_NONSEGMENT.${EXTENSION}

# Assuming the first column in the record is always numeric and it is the header of the record
# any line not following the above pattern will be treated as the data belong to the header record
# Skipping the first line in the file
echo " Processing the file $1..."
sed 1q $1 | tee $NON_SEGMENT_FILE >$SEGMENT_FILE
sed 1d $1 |while read line
do
firstCol=(`getColumnData $line`)
isRecordHeader=`isNumeric ${firstCol[0]}`;
if [[ $isRecordHeader =~ "0" ]]
then
if [[ `containsSegment ${firstCol[1]}` =~ "0" ]]
then
#The data has to be appended to the segment file
filetoAppend=$SEGMENT_FILE;
else
#the data has to be appended to the non segment file
filetoAppend=$NON_SEGMENT_FILE;
fi
echo $line >>"$filetoAppend"
else
echo $line >>"$filetoAppend"
fi
done

echo " Finished processing the file $1..."
echo " Generated the following files: $SEGMENT_FILE, $NON_SEGMENT_FILE"

please suggest wat changes to be done in the above script to look for the values in sixth column and search for pattern "VS KSDS"

Please stop making new threads for the same script. Go back to your previous thread.

1 Like
Moderator comments were removed during original forum migration.
1 Like