extract the value from the log using shell script extract the value from the log using shell script shell shell

extract the value from the log using shell script


With GNU grep:

grep -Po '[^ ]*(?=\.$)' file

or

grep -Po 'user \K[^ ]*' file

With awk:

awk -F "[. ]" '{print $(NF-1)}' file

or

awk -F "user " '{split($2,array," "); print array[1]}' file

or search for field with string user and print next field:

awk '{for(i=1; i<=NF; i++) if ($i=="user") print $(i+1) }' file

Output:

a8197zz


Try this sed command also

sed 's/.*user \([^ ]\+\).*/\1/' fileName

Output:

a8197zz


Following awk may help you in same.

awk '{sub(/\./,"",$NF);print $NF}'  Input_file

Output will be as follows.

a8197zz