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
1
vote
4 answers

Grep a word from a file

How can i grep a nearer word from a file ? E.g 04-02-2010 Workingday 05-02-2010 Workingday 06-02-2010 Workingday 07-02-2010 Holiday 08-02-2010 Workingday 09-02-2010 Workingday I stored above data in a file 'feb2010', By this commend i stored…
Kumar
  • 823
  • 3
  • 20
  • 43
1
vote
1 answer

How get info into variables from command output

I am run nginx -V and get like this: nginx version: nginx/1.18.0 built by gcc 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) built with OpenSSL 1.1.1f 31 Mar 2020 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2…
Petro
  • 11
  • 1
1
vote
2 answers

GREP multiple lines that are not next to each other

I have a text file that looks like this: landlord: John Smith has: house: 0 flat: 5 available: 1 cheap: 0 quality: 1 landlord: Will Hall has: house: 3 flat: 4 available: 1 cheap: 1 quality: 0 landlord: Marry Moe …
John Smith
  • 11
  • 2
1
vote
1 answer

Format export using grep and awk

I would like to export data from zimbra server, but it's export data in every new lines, my command: zmprov -l gaa -v domain.com | grep -e "zimbraForeignPrincipal: " -e "zimbraTwoFactorAuthEnabled: " -e "^mail: " but the result looks…
zuku
  • 61
  • 1
  • 7
1
vote
1 answer

Scan IP range for SSL/TLS versions and vulnerabilities with legible/greppable output

I'm looking to find computers on the network that are using older versions of tls/ssl. So far I've been using nmap's ssl-enum-ciphers and ssl-poodle scripts but the output isn't helpful as it shows every cipher available, eg : Nmap scan report for…
rambetherleu
  • 21
  • 1
  • 5
1
vote
1 answer

Append to crontab only if entry does not exist

I am looking for a programmatic way to append to crontab only if the entry does not exist. Also, the exit code must be 0 for both cases where the entry does not exist, or the entry exists. I tried: (crontab -l -u root 2>/dev/null | grep -F -v…
Justin
  • 5,328
  • 19
  • 64
  • 84
1
vote
1 answer

How to quickly check if specific keywords exist in a lot of log files in shell?

I have run a program that writes a lot of log files in a lot of directories. For example, there are hundreds directories, and every one includes thousands of log files. I need to find out the files those include the keywords "WARNN", "ERROR" and…
Leon
  • 169
  • 9
0
votes
2 answers

How to filler out iptable result base on certain fields and view it with tail command?

I have this log : Jan 26 01:05:47 server54 kernel: [41s58.6w4335] INPUT:DROP: IN=eth4 OUT= MAC=d3:ss:43:23:23:43 SRC=1.1.1.1 DST=127.0.0.0 LEN=40 TOS=0x00 PREC=0x00 TTL=254 ID=65259 PROTO=TCP SPT=53252 DPT=22 WINDOW=14600 RES=0x00 RST URGP=0 And I…
malloc
  • 103
  • 3
0
votes
0 answers

Creating a script for Kickstarting servers; issue with created softraid 1 server based on CentOS 7

First off; I am sorry if my title is incorrect, but I didn't want to "clutter" it too much. I am creating a bash script which is used to install various servers based on CentOS 6 and CentOS 7 with hardware raid and software RAID 1. So far I am doing…
HudsonHawk
  • 103
  • 2
  • 14
0
votes
1 answer

Filter ss process output without using grep

ss -p can give the process name, process id (PID) and the file descriptor associated with the connection. Example: ss -tuanp [...] tcp ESTAB 0 0 x.x.x.x:59594 x.x.x.x:993 users:(("thunderbird",pid=1985,fd=98)) [...] While the filter…
wget
  • 291
  • 2
  • 8
0
votes
2 answers

Parse Date from Text String in a 3 column format

I am given an array of lines from a text file. They look similar to this, and will always be structured like this: Full Tue Aug 27 10:59:43 2019 1 Incremental Tue Aug 27 11:16:41 2019 …
Kevin
  • 133
  • 1
  • 2
  • 14
0
votes
1 answer

grep for an array entry in a file

so I have a file step1 containing data like field [T]:0.000 heatstart [s]: 1.50E+1 a[a],b[b],[c[c],d 1.02E-1,2.31E-1,... 1.50E+1,4.26E-1,... ... and a file called var4 containing only the entry 1.50E+1. I used mapfile to get this entry as a…
nobody
  • 1
  • 1
0
votes
1 answer

How to create an alias that uses a value and grep on a remote server?

I need help, I can't create an alias with a variable to grep a file on a remote server. I have tried: alias searchword="ssh -t user@server "grep -i \"$1\" /root/file.txt\"" alias search="ssh -t user@server 'grep -i $1 '\'"/root/file.txt\'" If I…
xxmlud
  • 3
  • 3
0
votes
2 answers

grep exclude multiline pattern

Searching for multiline patterns in files with grep is trivial. Inverting that pattern not so much. Background: I want to create clean variable files without passwords so I can commit them into a repository. Example of a variable file containing an…
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
0
votes
1 answer

How do I grep last match in a range of files?

I have files named memOutput.X where X ranges from 0 to 47 in a directory. I want to see the line with the last occurrence of VmData in all these files. I can run grep VmData memOutput.0 | tail -1 to get the last match from one file but not sure…
nac001
  • 103
  • 4