Questions tagged [grep]

grep is a command-line tool for searching text patterns in files.

The grep utility searches a pattern (regular expression) in a text file. There are many options to control how matches are performed and how to display matches.

External references

Tutorials

Further reading

See also grep on Unix & Linux Stack Exchange for more detailed reading.

326 questions
2
votes
1 answer

How to use grep commend with variable

How can i use grep commend with variable ? I stored ' Feb 1 ' (future it will be changeable) to variable 'date'. Now i want to grep this variable 'date', How can i do this ?
Kumar
  • 823
  • 3
  • 20
  • 43
2
votes
1 answer

Extract a ids from text file

I have a text file live below { "data": { "assigned-entity-id": null, "assigned-entity-type": null, "availability-domain": null, "compartment-id": "ocid1.tenancy.oc1..dgfmmnusmgibmkdomuijsngimimfimfgiufmgifmdsfsdsgsmgsifmg", …
Am3Y
  • 67
  • 6
2
votes
3 answers

How to grab a word from a file using sed or grep

I am trying to pull a piece of text from a file to use as input for the next command. The word always starts with "JID_" and then some random numbers/characters after that. For example : SelectorSet Selector: InstanceID =…
2
votes
1 answer

CentOS command not found

When I login to my CentOS 7 Server I get a couple of errors. Similar command is: 'tty' bash: ls: command not found... Similar command is: 'lz' /usr/libexec/grepconf.sh: line 5: grep: command not found Yesterday I tried to install the jre 9 by using…
Jonas Heinze
  • 43
  • 1
  • 9
1
vote
1 answer

Not logic in docker filter

I have a named container that may or may not be up and if it is up I want to be able to kill all the containers but that one by name. Basically what I want is: docker kill $(docker ps -aq --filter="name!=") sadly the internal docker…
Itay Weiss
  • 133
  • 5
1
vote
0 answers

Why is sudo password entering lost

When I use sudo command and pipe it to another command, e.g. sudo dnf search foo | grep bar there is a prompt requiring to enter the password. Following this answer, sudo directly accesses the terminal to prompt the password. But I found that there…
1
vote
3 answers

text processing linux using grep awk or anything else

I want to replace in this string Wed Apr 10 06:44:10 UTC 2019 all whitespaces with comma and along with that trim off UTC part. What I have tried : var1="Wed Apr 10 06:44:10 UTC 2019" echo ${var// /,} This gives all spaces removed but how to trim…
Alex
  • 172
  • 1
  • 1
  • 8
1
vote
2 answers

Send email if script outputs string

I found this line: sh script.sh | grep 'NO' 2>&1 > grep.log && /usr/bin/mail -s "grep found something" m@mail.com < grep.log which will write the output of script.sh to grep.log and then email that to an email m@mail.com Is there anyway to remove…
Kohjah Breese
  • 171
  • 2
  • 13
1
vote
1 answer

How can I use an iperf output and only grep Interval and Bandwidth?

I am trying to get the output from the command iperf -c 10.0.0.1 -t 3600 -i 2 And only need the Interval and bandwidth fields listed for the entire hour of logging. I haven't used grep or awk in years upon years. Help would be awesome! Sample…
Gutsygibbon
  • 113
  • 1
  • 6
1
vote
3 answers

Grep last match from file

I'm running the following command against a log file and only wanting to get the last/latest match. Sometimes there may only be one match, other times there may be multiple, which is causing an issue for me since the following command is returning…
Godzilla74
  • 135
  • 1
  • 7
1
vote
1 answer

Grep --only-match without new line

I want to use grep command to extract some strings from my data file. data file format a=1,b=2,c=3, a=4,b=5,c=6, I want the out format a=1,c=3, a=4,c=6, I tried the below command grep -Po 'a=.*?,|c=.*?,' data But the output format is incorrect.…
tomli
  • 21
  • 5
1
vote
1 answer

grep does not work in particular folder on centos?

It's a bit strange with the grep command. When I am in the mail folder, it always produces help text. At first, I thought I had wrong synxtax but it is working on its parent folder. What could be the cause? TIA! [xx]$ grep "abc" *.out grep: invalid…
Dat TT
  • 111
  • 2
1
vote
1 answer

Matches in color, others just shown

I'm just trying to get grep to show all the lines, but the ones that match should have the matching text colored. Specifically I need this for something like this: tail -f file.log | grep --color Exception Unfortunately I don't see any option in…
1
vote
0 answers

Legal Discovery - how to search .eml files for keywords and copy the results to another folder on macOS/Unix?

I've got a Kerio Connect mail server that saves all of it's emails in a relatively standard mail spool folder structure as raw .eml files. I've been tasked with performing a keyword search against some of the user's mailboxes for keywords and email…
Kai Howells
  • 83
  • 1
  • 5
1
vote
0 answers

Grep - Looking for non printable or higher range ascii characters

We faced an issue when someone copied a string from somewhere in one of the metadata xml files that contained ascii characters 239 (0xef), 191 (0xbf), 189 (0xbd) We fixed the problem in known file, but I would like to check if similar problem exists…
user871199
  • 185
  • 5