Hi anyone,
since Sunday I try to create a schellscript that reads the last 10 lines of text out of a log and parses the guid's of the entrys in there.
The log looks like this:
for line in $(tail -n 10 $log );
do
#is it a line we want to catch??
if [[ $newline =~ [C][l][e][n][t][e][r][n][f][o][:] ]]; then
#get the guid
if [[ $newline =~ [c][l][_][g][d][\\](................................) ]]
then
guid="${BASH_REMATCH[1]}"
echo found guid
echo $guid
else
echo error, no guid
fi
done
This works only if the given guid in the logifle starts with a Letter, if the first Character is a number, it gets some wrong crap out.
I am looking forward to find help,
S0lll0s
PS: pls dont mess my code up so i dont understand it anymore, thx:)
---------- Post updated at 11:03 AM ---------- Previous update was at 10:50 AM ----------
This seem to work OK for me:
Note:
Uses read -r to avoid \ processing
No need for all the [ and ] in match
No "t" in ClienUserinfo
tail -n 10 $log | while read -r
do
#is it a line we want to catch??
if [[ "$REPLY" =~ ClienUserinfo: ]]; then
#get the guid
if [[ "$REPLY" =~ cl_guid\\(................................) ]]
then
guid="${BASH_REMATCH[1]}"
echo found guid
echo $guid
else
echo error, no guid
fi
fi
done
@ Chubler_XL
just misspelling, its "ClientUserinfo"
Somehow it doesnt work, it just reads a few lines, and a few it doesnt. also it doesnt read the whole line, it stops after a few lines.
tail -n 10 $log | while REPLY=read -r
do
#is it a line we want to catch??
if [[ "$REPLY" =~ ClienUserinfo: ]]; then
....
but it didnt work.
@Kurumi i dont get how i should read the variable now. I tried adding "print $s" at the end but it returned the whole last 10 lines.
tail -n 10 $log | sed '/ClientUserinfo/!d;s/.*cl_guid\\//;s/\\.*//' | while read
do
guid="$REPLY"
export guid
export
done
echo "$REPLY"
it showes this:
...
export __CF_USER_TEXT_ENCODING="0x1F5:0:3"
export guid="66F1365D96239BB0C6BB7CE6A74C064B"
but if i quit the script and type
"export"
guid isnt set again
If you are sure that within the 10 last line of your log file, you will never get more than 9 guid, you can (and if your script has already saved $1 $2 ... arguments in some other variables you can just replace your whole loop with something like :
set -- `tail -n 10 $log | sed '/ClientUserinfo/!d;s/.*cl_guid\\//;s/\\.*//'`
guid=`tail -n 10 $log | sed '/ClientUserinfo/!d;s/.*cl_guid\\//;s/\\.//'`
produces this error:
sed: 1: "/ClientUserinfo/!d;s/. ...": bad flag in substitute command: '\'
and your last example never prints out ANYTHIN with tst =
199E
1BCC
0A9B
0AA1
15A5
15AD
0AA2
15A6
15AC
also
tail -n 10 $log | sed '/ClientUserinfo/!d;s/.*cl_guid\\//;s/\\.*//'
echo $REPLY