Kaan Murzoğlu
Kaan Murzoğlu

Reputation: 45

How can I cut the string

This is my log file

 
Started by user [[^8mha:////4Ogh/8s/t6WCscPP1xh6+eb52nXryfTykwZL/ZyDxeq/AAAAlx+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAzWEgZu/dLi1CL9xJTczDwAj6GcLcAAAAA=^[[0madmin

My code

echo "Job User= $(cat /home/kaanmrzl/log.txt | grep "Started by user" | cut -d"[" -f5 )"

Output

 Job User= 0madmin 

what i want is output`

 Job User= admin 

Upvotes: 0

Views: 76

Answers (3)

deiviiz
deiviiz

Reputation: 1

Using your code you just need to add one more line:

CORE=$(echo $(cat /home/kaanmrzl/log.txt | grep "Started by user" | cut -d"[" -f5 ))
IDUSER=$(echo "Job User =" ${CORE:2})

Upvotes: 0

UtLox
UtLox

Reputation: 4154

You mean something like that:

echo "Job User= $(sed '/^Started by user/s/.*=^\[\[0m//' /home/kaanmrzl/log.txt)"

Upvotes: 1

RavinderSingh13
RavinderSingh13

Reputation: 133458

Could you please try following(if you are ok with awk, tested with given samples).

awk -F"\\[\\[" '/^Started by user/{print substr($3,3)}'  Input_file

This code removes first 2 characters from 3rd field where field separator is set as [[ by awk code's -F.

Upvotes: 1

Related Questions