Skip to main content

All Questions

1 vote
1 answer
2k views

grep: use square brackets to match specific characters

So I am experimenting with the power of grep using this resources The problem I am currently encountering is that it doesn't seem to work as I intended. so I have an demo.txt file that contains foo....
jxhyc's user avatar
  • 181
5 votes
2 answers
26k views

How do I grep multiple patterns from a pipe

I want to find three patterns in a list. I tried typing $ pip3 list | grep -ei foo -ei bar -ei baz but the shell throws a broken pipe error and a large Traceback. How do I grep for multiple ...
bit's user avatar
  • 1,116
4 votes
3 answers
15k views

How can search for both single quotes and double quotes in a grep search?

When I do a search bindkey in the zsh plugins directory for key conflicts I get responses from both the .zsh script files and .md files, and some of the zsh readme files use a double quote in the ...
vfclists's user avatar
  • 7,619
10 votes
3 answers
17k views

shell test whether multiple lines string contains specified pattern in last line

I want to determine whether a multi-line string ends with a line containing specified pattern. These code failed, it doesn't match. s=`echo hello && echo world && echo OK` [[ "$s" =~ ...
gzc's user avatar
  • 325
9 votes
1 answer
1k views

Why does `grep fil*` fail?

I found echo file|grep fil* fails, but echo abcd|grep abc* succeeds. I don't understand it, can someone explain?
tmpbin's user avatar
  • 783
3 votes
2 answers
4k views

Define a variable to awk pattern matching from bash

I am trying to grab 100 lines after the text "time: X" with X in {0,40,80,...,200}. Here is what I have so far: #!/bin/bash start=1 end=5 for i in $(seq $start $end);do j=$(($i*40)) awk '/time: ...
user164723's user avatar
1 vote
2 answers
2k views

How to search parenthesis by ack

I want to search for a parentheis ( using ack, but neither using ( nor \( worked. The first one ("(") is recognized as a multiple line command. The second one ("\(") is treated as an invalid regular ...
ironsand's user avatar
  • 5,265
10 votes
4 answers
6k views

Regular expression using \\ vs using \

Why does grep e\\.g\\. <<< "this is an e.g. wow" and grep e\.g\. <<< "this is an e.g. wow" do the same thing? If I add a third slash, it also has the same result. BUT, once I ...
Wyatt Grant's user avatar
5 votes
1 answer
7k views

command: ls /etc | sort | grep d* is yielding no results but ls /etc | sort | grep p* lists entire directory

I am playing around with piping and grep tonight. I know that grep uses regex and that * means 0 or more occurrences of the preceding character. So the way I understand it is that if I do the ...
Brad Harris's user avatar
8 votes
5 answers
15k views

bash event not found trying to match and exclude parenthesis in grep

In a very long line I'll summarize with: (foo),(bar,baz(word,right),(end) I want to print only: (bar,baz(word,right To match the second parenthesis, I exclude the word that follows the third ...
Philippe Blayo's user avatar
2 votes
2 answers
1k views

What does this regex mean?

I was working on the conversion of Unix newline to Windows newline. I tried to unix2dos but it gave me some binary error, so I looked it up and stumbled upon this regex sed 's/$'"/`echo \\\r`/" input....
Max's user avatar
  • 705
8 votes
3 answers
33k views

Escaping * with Regular Expressions and Grep

I have a file that has unique lines that start with 2 stars (**). However when I run a grep command for grep \*\* fileName I get all of the lines in the file. This is very unusual, and what I see ...
monksy's user avatar
  • 743
3 votes
1 answer
192 views

find utility does not recognize bracket notation

I've two files in the current folder: submitWeb.m submit.m the following find does not show the two files: find . -regex .*submit\(Web\)?\.m But the above regex expression works fine in emacs ...
gongzhitaao's user avatar
1 vote
2 answers
3k views

Weird zsh grep -P behaviour

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 ...
Nakilon's user avatar
  • 144
806 votes
13 answers
1.8m views

How do I grep for multiple patterns with pattern having a pipe character?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
Dan's user avatar
  • 9,532

15 30 50 per page