Preserve ls colouring after grep’ing

Your grep is probably removing ls‘s color codes because it has its own coloring turned on. You “could” do this: ls -l –color=always | grep –color=never pattern However, it is very important that you understand what exactly you’re grepping here. Not only is grepping ls unnecessary (use a glob instead), this particular case is grepping … Read more

Extract column using grep

You need to use awk: awk ‘{print $1,$3}’ <namefile> This simple command allows printing the first ($1) and third ($3) column of the file. The software awk is actually much more powerful. I think you should have a look at the man page of awk. A nice combo is using grep and awk with a … Read more

grep: repetition-operator operand invalid

$ grep -Pio ‘(?<=heads\/)(.*?)(?=\n)’ text.txt # P option instead of E If you use GNU grep, you can use -P or –perl-regexp options. In case you are using OS X, you need to install GNU grep. $ brew install grep Due to recent changes, to use GNU grep on macOS you either have to prepend … Read more

Piping tail output though grep twice

I believe the problem here is that the first grep is buffering the output which means the second grep won’t see it until the buffer is flushed. Try adding the –line-buffered option on your first grep: tail -f access_log | grep –line-buffered “127.0.0.1” | grep -v “.css” For more info, see “BashFAQ/009 — What is … Read more

Include header in the ‘grep’ result

The following means you only need type the command once (rather than using && and typing it twice), it’s also quite simple to understand. some-command | { head -1; grep some-stuff; } e.g. ps -ef | { head -1; grep python; } UPDATE: This only seems to work for ps, sorry, but I guess this … Read more

Search for files & file names using silver searcher

According to the man page of ag -G –file-search-regex PATTERN Only search files whose names match PATTERN. You can use the -G option to perform searches on files matching a pattern. So, to answer your question: root@apache107:~/rpm-4.12.0.1# ag -G cpio.c size rpm2cpio.c 21: off_t payload_size; 73: /* Retrieve payload size and compression type. */ 76: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)