LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-29-2020, 04:28 AM   #1
nextStep
Member
 
Registered: Aug 2018
Posts: 32

Rep: Reputation: Disabled
unable to grep the log file


Hi All,

I am trying to grep the below pattern from a remote server log.The remote log file have left/right parenthesis . I believe the grep is breaking when it reaches the left/right parenthesis,hence provided the regular expression in the grep statement.Could you please advise how to resolve this.

Log file as below.

ERROR Cruise is not available due to error while checking cruise price. Error detail: (Service.Itinerary)

Code:
ssh username@${host[i]} grep -Poi "ERROR Cruise is not available due to error while checking cruise price. Error detail: '(?<=\().*(?=\))'"  /home/folder1/file.log
 
Old 06-29-2020, 05:08 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,169

Rep: Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126
Think about what you're grepping - it makes no sense to grep all that text (which you presumably don't really want) plus the bit in the brackets that the perlre defines. What is the "-o" supposed to indicate if you grep the entire line ?.
Get rid of all the text, and also the single quotes - just use the re and see what you get.
 
Old 06-29-2020, 06:05 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,167

Rep: Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393Reputation: 7393
I would do the following:
1. ssh user@host cat logfile | grep ...
that will make grep run locally, do not need to send the grep pattern over the line
2. try a simple regex first. Replace "strange" chars with a simple . (dot).
 
Old 06-29-2020, 06:18 AM   #4
nextStep
Member
 
Registered: Aug 2018
Posts: 32

Original Poster
Rep: Reputation: Disabled
Thanks syg00 for the insights.

I tried with the suggestion given but couldnt get the results.
Code:
ssh username@hostname grep -s '(?<=\().*(?=\))' /home/folder1/file.log

bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `grep -s (?<=\().*(?=\)) /home/username/file1.log'

So a little more background of this issue is

I am trying in getting a warning notifications if the exact match is found along with the package name defined inside the parenthesis. [In the log file the same error text appears but for different packages one example as -->((OpenJawFlightPriceCheckProvider.lambda$checkPrice$0) which we don't want to consider ]
With that said removed all the other sentences and added the option "s" in the below code

Code:
ssh username@${hostname[i]} grep -s 'ERROR Cruise is not available due to error while checking cruise price' /home/folder1/file.log | wc -l
The above resulted in getting the output as 1 which is correct , but if we change the package name (inside the parenthesis) the grep gets the same count. This is the issue which am trying to resolve.
 
Old 06-29-2020, 06:34 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,169

Rep: Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126Reputation: 4126
I misunderstood your requirements. The perlre will match anything in the brackets, so won't add any functionality. But you do need the "-P" when using perlre in grep.

To manage counts on specific text in the brackets, I'd use awk, but perl itself rather than perlre in grep would be the way to go.
 
1 members found this post helpful.
Old 06-29-2020, 06:37 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,398
Blog Entries: 3

Rep: Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778Reputation: 3778
In addition to the above advice, I would wrap the remote components in quotes.

Code:
# untested:
ssh username@hostname 'grep -P -s "(?<=\().*(?=\))" /home/folder1/file.log'
However, the underlying problem might be that you need to tell grep to parse the Perl-compatible Regular Expression as such. What you have is not POSIX nor Extended POSIX so I would guess that it is PCRE.

Edit: already covered.

Last edited by Turbocapitalist; 06-29-2020 at 06:38 AM.
 
1 members found this post helpful.
Old 06-29-2020, 08:17 AM   #7
nextStep
Member
 
Registered: Aug 2018
Posts: 32

Original Poster
Rep: Reputation: Disabled
Thanks All,issue is resolved
 
  


Reply

Tags
grep, regex


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to log internal-sftp chroot jailed users access log to /var/log/sftp.log file LittleMaster Linux - Server 0 09-04-2018 03:45 PM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
Searching var/log/updates.log using grep noobee26 Linux - Newbie 15 06-27-2011 01:42 PM
hi ,i have to grep a series say 98782 from a file containing series how can i grep it sushil.cool Linux - Newbie 6 05-25-2010 06:27 AM
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration