LinuxQuestions.org
Visit Jeremy's Blog.
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 03-23-2018, 10:03 PM   #16
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,005

Original Poster
Rep: Reputation: 34
Letting grep waiting, playing with regexes in Vim


Letting grep and shell waiting, I am playing with regexes in Vim for sometime.

Look at these two Vim commands:

Code:
:%s/C\[[PA][av][[:print:]\n]\+\]//gec

:%s/C\[[PA][av][[:print:]  ]\+\]//gec
Spaces are *only* for easy eye comparison! The only change in these 2 commands is the "\n" inside the bracket group. Vim seems to consider \n a nice char (or charset), which is good for me.

But those two do not work. The first command will match too much... I must always consider the next ']' as the C expression end. Ideas?

Idea! There is something about things that match as few or as much, isn't? What is the name of that? (going to search after posting this)
 
Old 03-23-2018, 10:35 PM   #17
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,005

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by AwesomeMachine View Post
OK, I looked at the SGF format. There is no binary data used in them. There are nonprinting characters, which are not the same as binary data. I suggest you just tell the community exactly what you want to do, post part of the file inside quote tags, and let everyone look at what you have. I'm rest assured grep is not the tool to use for your project.
Maybe I should have mentioned the SGF in the first post, but I guessed the answer would be just a hidden or uncommon regex detail.

No binary data in SGF? Great! The SGF files I have contain game records! (weiqi is a board game). So files may have move comments ( https://www.red-bean.com/sgf/properties.html#C in the spec I gave above), and these comments may be in any encoding. How much binary that is or not, please tell me!

I do not generate the files. And what I am trying is also *not* a project (or part of one, of any kind). I am not trying some different, or far, from what I have initially asked.

Last edited by dedec0; 03-23-2018 at 10:51 PM.
 
Old 03-24-2018, 01:24 AM   #18
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,511

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Maybe it's not been said before, but if grep finds a match, it prints the entire line. So if you looking for everything but ], in every line that grep finds ] it won't output any part of that line. But if it doesn't find ] in a line, it will print the entire line.
 
1 members found this post helpful.
Old 03-24-2018, 07:13 AM   #19
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,230

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
Quote:
Originally Posted by dedec0 View Post
Maybe I should have mentioned the SGF in the first post, but I guessed the answer would be just a hidden or uncommon regex detail.
Do you have a real data example? The grep regexp I posted works. So I don't know...
 
Old 06-23-2018, 10:03 PM   #20
dedec0
Senior Member
 
Registered: May 2007
Posts: 1,005

Original Poster
Rep: Reputation: 34
Arrow

Quote:
Originally Posted by AwesomeMachine View Post
Maybe it's not been said before, but if grep finds a match, it prints the entire line. So if you looking for everything but ], in every line that grep finds ] it won't output any part of that line. But if it doesn't find ] in a line, it will print the entire line.
That is not true. Grep may only print matching parts. I just checked this in the man page:

Code:
   -o, --only-matching
      Print  only  the  matched (non-empty) parts of
      a matching line, with each such part on a 
      separate output line.
( :
 
1 members found this post helpful.
  


Reply

Tags
grep regex gnu


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
[SOLVED] Grep regex: bracket fanoflq Linux - Newbie 6 03-06-2017 02:03 AM
Need Regular Expression (regex) help [Java] dwhitney67 Programming 4 08-24-2013 03:24 AM
[SOLVED] sed edit the line above a regex expression corcodelagaze Programming 9 02-25-2012 09:52 AM
regex expression ksmatthews Linux - Software 5 01-11-2012 11:43 AM
[SOLVED] grep Bracket Expressions Star_Gazer Linux - Newbie 2 04-10-2010 09:30 PM

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

All times are GMT -5. The time now is 09:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration