LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to manipulate values in a log file (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-manipulate-values-in-a-log-file-4175547919/)

ablopera 07-13-2015 11:31 PM

How to manipulate values in a log file
 
Hi Guys, need some assistance on the log file being created by my script. Please see below details:

[/code]
Script:

#!/bin/bash

# Get the first value, which we will compare to the other
# values further down in the file.
STATIC=$(sed -n 4p POSData.log)

# Loop through the file to see if the STATIC value
# matches the other values VALUE
for i in $(seq -w 01 63); do
if grep -q "TID $i" POSData.log; then
VALUE=$(grep -A 3 "TID $i" POSData.log | tail -1)
if [ $STATIC == $VALUE ]; then
echo "Match."
else
echo "TID $i PLU Count ($VALUE ) is not matched with the Server Count ($STATIC )" >> PLUComp.log

fi
fi

done

============================

[/output]
Source Log

LINUX SERVER
count
--------
331435
(1 row)

=======================

TID 01
count
--------
331435
(1 row)

=======================

TID 02
count
--------
331435
(1 row)

=======================

TID 03
count
--------
331439
(1 row)

=======================

TID 04
count
--------
331435
(1 row)

=======================

TID 05
count
--------
No Route To Host
(1 row)

=======================

TID 06
count
--------
331438
(1 row)

=======================

TID 07
count
--------
No Route To Host
(1 row)

=======================

TID 08
count
--------
No Route To Host
(1 row)

=======================

TID 09
count
--------
No Route To Host
(1 row)

=======================

[/output]
Output Log

TID 03 PLU Count ( 331439 ) is not matched with the Server Count ( 331435 )
TID 05 PLU Count (No Route To Host ) is not matched with the Server Count ( 331435 )
TID 06 PLU Count ( 331438 ) is not matched with the Server Count ( 331435 )
TID 07 PLU Count (No Route To Host ) is not matched with the Server Count ( 331435 )
TID 08 PLU Count (No Route To Host ) is not matched with the Server Count ( 331435 )
TID 09 PLU Count (No Route To Host ) is not matched with the Server Count ( 331435 )

What I want to do is to reflect the following below in the logfile.

If client PC is online reflect this:
TID 03 PLU Count ( 331439 ) is not matched with the Server Count ( 331435 )

If the client PC is offline/cannot be reached, reflect this:
No Route To Host

I added additional condition in the script, but to no avail.

syg00 07-14-2015 12:07 AM

Quote:

Originally Posted by ablopera (Post 5391076)
I added additional condition in the script, but to no avail.

Show us - and use [code] ... [/code] tags when posting code (or output).

ablopera 07-14-2015 12:39 AM

Quote:

Originally Posted by syg00 (Post 5391085)
Show us - and use [code] ... [/code] tags when posting code (or output).

Hi syg00, got it. My apologies, Im only new here and still learning. Will do it on my succeding post. Thanks.


All times are GMT -5. The time now is 06:07 AM.