how to get specific character from a log file in linux

ANSWER

Assuming that (1) the log file looks as it is AND (2) it is multi-line, then a simple Linux grep command like below should work (even with multiple lines of that line you’re looking for in one log file):

INPUT | Tested it on dummy logs from sample

COMMAND | grep -Pn "^Id\s+:\s+(.*)$" *.log

OUTPUT |

log101.log:2:Id : UN123P

log102.log:2:Id : HELLO321

log103.log:2:Id : STUDE23P

log104.log:2:Id : Lorem

log104.log:7:Id : IPsum

log104.log:12:Id : Dolor

have a log file , having multiple contents inside the file like and example below is the content of U123.log . I have n number of logs..

Accepted password for hoover from 10.0.2.2 port 4792 ss

Id : UN123P 

ID_MTCH : UnixProduction

Accepted password for hoover from 10.0.2.2 port 4792 ss

Accepted password for hoover from 10.0.2.2 port 4792 ss

Is there any we can fetch “Id : UN123P” as an output of linux command. We have some 1000’s of logs and from all the logs , trying to fetch the value only starts with ID : and output as “Id : UN123P”

Pls suggest

Go to Source
Author: Arya