Home > bash > using grep --perl-regexp

using grep --perl-regexp

January 27Hits:1

this is a sample output of ls

$ ls -lAF -rw-------  1 martin martin  168 Jan 25 23:26 aaa -rw-------  1 martin martin  168 Jan 25 23:26 bbb -rw-------  1 martin martin  168 Jan 25 23:26 ccc 

I would like to colorize the user and group entries. However, my syntax only colorizes user,but not the group:

ls -lAF | grep --color -P '^\S+\s+\S+\s+\K\S+' 

I don't understand what the \K exactly means. How could I match both martin martin in my sample output?


\K marks the start of the region to color.

See man pcrepattern for details.

The escape sequence \K causes any previously matched characters not to be included in the final matched sequence.

That means you need:

ls -lAF | grep --color -P '^\S+\s+\S+\s+\K\S+\s+\S+'

Related Articles

  • using grep --perl-regexpJanuary 27

    this is a sample output of ls $ ls -lAF -rw------- 1 martin martin 168 Jan 25 23:26 aaa -rw------- 1 martin martin 168 Jan 25 23:26 bbb -rw------- 1 martin martin 168 Jan 25 23:26 ccc I would like to colorize the user and group entries. However, my s

  • Is there a way to let Emacs' regexp based commands such `query-replace-regexp` use Perl regexp?January 18

    Is there a way to let Emacs' regexp based commands such query-replace-regexp use Perl regexp? I am hoping there is some reasonably simple way to achieve this, for example, by adding code in .emacs. --------------Solutions------------- Sorry, no, ther

  • Grep perl syntax and copyright characterJanuary 3

    I am trying to pull some links out of text that I downloaded of off the internet using grep, but keep getting "Aborted (core dumped)". When using grep I tend to use -P as I prefer to use perl syntax (and I like to prevent greediness using ?). Gr

  • awk, sed, grep, perl- which to print out in this case?March 25

    I have this syntax in a file (http response times from analog): <thead><tr><th class="x">seconds</th><th class="R">reqs</th><th class="r">%reqs</th><th class="B">

  • Strange execution time for recursive grepMarch 5

    I'm on a Linux Ubuntu machine, grepping a large number of files. Can anyone explain these timings? >time grep -nIr acct_margin * [... 3 results ...] real 0m0.555s user 0m0.400s sys 0m0.150s Case insensitive: >time grep -niIr acct_margin * [... 3 res

  • Get package use flagsJanuary 6

    How can I get list of specific package's use flags? So, there are at least 2 ways to do that: emerge -pv $PACKAGENAME equery uses $PACKAGENAME But these commands returns to many noisy information. All I want is simple list like useflag1 useflag2 usef

  • How can I list all packaged installed by me?

    How can I list all packaged installed by me?April 9

    I am trying to clean my installation up a bit, so I decided to clean up my packages a bit. However, I'm having trouble with that: My wish is to make apt-get list all packages installed by me. If I list every package, I also see the dependencies of my

  • How can I add Times New Roman WITH IPA EXTENSIONS?October 29

    I'm looking for an easy way to install the Times New Roman font (which I need for my dissertation) that has the IPA extensions. The one that comes with the ttf-mscorefonts-installer does not have them, and I was hoping that someone here would know wh

  • How can I force sed to continue parsing when it hits an "invalid" character?November 26

    I have a big playlist in .pls format (created with deadbeef playing software) which also contains some badly-encoded strings. Whether this is a bug in deadbeef or one of its plugins does not really interest me, though, since I just want to cut off fr

  • Why are the CPU frequency timing statistics all zeros?February 17

    The cpufreq timing statistics are all zeros: $ sort --unique /sys/devices/system/cpu/cpu*/cpufreq/stats/time_in_state | column 1600000 0 2100000 0 2600000 0 3100000 0 1700000 0 2200000 0 2800000 0 3300000 0 1900000 0 2400000 0 2900000 0 3400000 0 200

  • How to read/ modify freetds.conf (for ODBC) using augtool or similar in bash script?January 22

    How can I get augtool (augeas) or a similarly common tool to work with freetds.conf, so I can automate some configuration in a bash install script? This doesn't seem to work: augtool print "/files/etc/freetds/freetds.conf" However, this works (b

  • How to parse commands from a text file to a bash script in the CLINovember 15

    I have a bash script which getting the data by this: $ ./script.sh var1 var2 var3 What I want is to have the variables in a text file in the same format like I type in the command line. input.txt var1 var2 var3 And I want somehow to feed this txt to

  • Which regular expression standard is used in grep?April 12

    Is the regular expression standard used in grep POSIX + ASCII or something else is mixed in? --------------Solutions------------- That all depends on which flags you pass to grep. The normal flagless grep (which is the same as passing -G) uses "Basic

  • What is the difference between `grep`, `egrep`, and `fgrep`?August 3

    Can any one tell me the technical difference between grep and egrep, and fgrep and provide a suitable example? When do I need to use grep over egrep and vice versa? --------------Solutions------------- egrep is 100% equivalent to grep -E fgrep is 100

  • grep equivalent of the kwrite regex [A-Z][A-Z]+February 10

    So, it took me ages, but I finally learned to think in terms of regular expressions, thanks to using them in kwrite. But I still don't know how to translate that knowledge to grep. I love my grep, when I know what I'm doing with it, but the manual ha

  • Weird zsh grep -P behaviourMay 12

    I connect to server with PuTTY from Windows. I have a long yet not touched (I suppose) by hands of local admin config: $ cat /opt/jira/.subversion/config ... ### must be enabled, which is typically done by setting the ### 'enable-auto-props' option.

  • How to grep for special character NUL (^@^@^@)November 17

    File: O000000667520994000000074720121112000000N^@^@^@ I used the below command but it doesn't work. grep "^@^@^@" * --------------Solutions------------- You can grep for any characters including control/non-printable characters in perl-regexp mo

  • Why escaped single quote doesn't work in grep?May 20

    I am trying to match a string: * * * * * /usr/local/bin/growlnotify -t 'helloTitle' -m 'helloMessage' -n 'myApp' -sw with: crontab -l | grep '^[^#].*/usr/local/bin/growlnotify.*\-n \'myApp\'.*$' it doesn't work: nothing matched. But: crontab -l | gre

  • Forcing Bash to use Perl RegEx EngineJuly 26

    As you may already know, a lot of the features modern RegEx engines support (back referencing, lookaround assertions, etc.) are not supported by Bash RegEx engine. Following is a simple Bash script I have just created to try to explain what my end go

  • grep for multiple strings in files, and then list the files in the order of sizeAugust 6

    I am in a folder with lots of .txt file, I would like to find all the files which contain both stringA and stringB (not necessarily on the same line), then list these files in the order of the size (from small to big) I have tried the follows, but it

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.654 s.