#!/bin/bash

if [ $# -ne 2 ]; then
	echo "This script extracts a log lines related to the particular cell."
	echo "The extracted relevant lines are printed on the std output."
	echo
	echo "syntax: $0 log.txt cellID"
	exit 1
fi

LOG="$1"
ID="$2"

echo "Extracting cell ID $ID from log file $LOG ."

# not extracting yet
EXTRACTING_CMD=""

cat "$LOG" | while read line; do

	# header line?
	if echo "$line" | grep -q "\*\*\*\*\*   \*\*\*\*\*"; then
		# yes

		# header line of the desired cell?
		echo "$line" | grep -q "cell ID=$ID"
		if [ $? -eq 0 ]; then
			EXTRACTING_CMD='echo "$line"'
		else
			EXTRACTING_CMD=""
		fi

		#echo "HEADER DETECTED: EXTRACTING_CMD=$EXTRACTING_CMD"
	fi

	eval $EXTRACTING_CMD
done

