help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading entries from file and applying an action


From: goncholden
Subject: Reading entries from file and applying an action
Date: Mon, 06 Jun 2022 19:56:08 +0000

I have the following line that reads telemetry data from a logfile when

"File:" or "+" is encountered. I am setting the variable action to either

continue or break, then running the command after the last + entry.

The "action=break" does not execute the action, only when reaching *) do

the commands "continue" and "break" execute.

One can either have

File: Value

or

File: Value

+ Value

+ Value

+ Value

The task is to capture the values for the "File" field.

If "+" is encountered, I will read through all subsequent values until the last 
"+" is encountered.

It could be that this is a weird way

of implementation

action=

"continue"

while

IFS=

read

-r telemetry;

do

attrib=

"

${telemetry%[[:blank:]]*}

"

case

$attrib

in

(

"File:"

)

# "File:" field name has been reached.

field=

"File"

; action=

"break"

;;
     (

"+"

)

# Detected the + continuation character

[[

"

$field

"

==

"File"

]] && action=

"break"

;;
     (*)

# action="continue"

#   Ends current iteration, resuming at next iteration.

#   Read next line in logfl, because "File" not yet reached.

# action="break"

#   Ends current iteration, exiting from the while loop.

#   Exit logfl reading after end of field "File".

$action

;;

esac

done

<

"

$logfl

"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]