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

learn more… | top users | synonyms

0
votes
1answer
31 views

Does find Command Do Match For Regexp Because Of Implementation?

In this case discussed: find (GNU findutils) 4.5.11 grep (GNU grep) 2.20 Let's say I have a directory that contains a bunch of files. I want to find the files named jtobdops02.key and jtobdops.02.cer....
0
votes
1answer
49 views

Monitoring Server Connections - Netstat formatting issue

I have had a few issues with a server recently. So i just wanted to leave a window showing the unique and IP's of connected devices. I have been using: watch -n 5 "netstat -tn 2>/dev/null | grep :...
3
votes
1answer
42 views

Get contents of a file from first instance to last instance of some arbitrary string

How can I view in less from the first instance of some arbitrary string "foo" to the last instance? This arbitrary string will be on most every line of the log. I don't want to do grep "foo" bar.log |...
0
votes
1answer
55 views

How to grep response to figure out how many calls got timed out?

I have a curl command which is calling one of our service so if my service timesout, it returns JSON response like below: [{"results":{"response":null},"error":{"errorCode":1001,"message":"Service ...
0
votes
2answers
46 views

Bash Script with Multiple Lines and Grep

I have output from a specific command that can provide the number of times an application has been marked as 'used' on an OS X system. The command is mdls. The output looks similar to the following (...
0
votes
2answers
50 views

insert complex line before or after complex line

i have file with complex text print("ERROR: passwords don't match") password = hash_func(password.encode("UTF-8")).hexdigest() i need to insert this text between them with open('/etc/openvpn/...
-1
votes
1answer
40 views

Searching for most recent file (Display Unique)

If i have a Folder structure with 10 Sub dirs Each sub folder has the possibility to hold a version of a file (Older or newer) "Poor folder structure." I was looking to use Find to locate all files ...
0
votes
0answers
35 views

How to use gnu parallel to improve grep within while a loop [duplicate]

I have this loop as you see it makes two greps. The files are huge and grep are very slow.How I can implement gnu parallel in this loop? while read lemma stem POS do date "+%T ${lemma}..." grep -E " ...
0
votes
3answers
65 views

Grep in many directories, but only look in each dir's specific subdirectory, not all sub dirs

My case: dir1 subdir1 FooFile subdir2 dir2 subdir1 FooFile subdir2 So, if I cd dir1, I can easily do something like find . | xargs grep "Foo" in order to list the names of ...
6
votes
1answer
88 views

Perl one liner to find words longer than 63 characters

I have a number of XML files containing sanskrit texts to be converted to tex. Latex has a maximum of 63 characters per word for its hyphenation to work, everything longer than that will not be ...
3
votes
1answer
69 views

Remove files with match only from some subdirectories

I have a directory with several subdirectories; in each of these, I have some files. I want to perform a grep only for some subdirectories to find those files that match the query and remove them; ...
1
vote
2answers
39 views

Sed from line 6 on from all txt files and being able to output all the results in a single file

I need to sed from all *.txt files from line 6 until the end All the results should be in a new single file with the name of each file preceding the results Example: Having different txt files the ...
0
votes
2answers
53 views

using awk to unzip files in directory

I have some zip files in directory when I need to unzip each in specific dir I used ls | awk '{ print "unzip " $1 " -d " $1} ' unzip p21286665_121020_Linux-x86-64.zip -d p21286665_121020_Linux-x86-...
45
votes
2answers
4k views

Why is egrep [wW][oO][rR][dD] faster than grep -i word?

I've been using grep -i more often and I found out that it is slower than its egrep equivalent, where I match against the upper or lower case of each letter: $ time grep -iq "thats" testfile real ...
-1
votes
1answer
45 views

how can i extract the second and third word of a line{that starts with 9} from a file where words are seperate with |? [closed]

case "$3" in -id) echo "Lines matches with the pattern $4 :" #grep -oP $4 $2 ;; esac
-1
votes
1answer
29 views

Remove pattern from a line in file with Grep/sed/awk combo, pattern is another column

I have two columns (or could separate as two files) in a huge file and i need to remove the duplicate city name in the state/area column. los angeles los angeles ca, usa, west new york ...
3
votes
3answers
46 views

Strings - Extract File Version Recursive

I have been using strings to extract and compare file versions between directories. I don't seem to be able to do this recursively. The method I have been using per file is: strings -e l ...
5
votes
3answers
52 views

How can I get the seprate results for each pattern from multiple grep

I would like to search 14 different patterns within 100 files. At the moment what I tried cat s_3_2_*_qseq.txt | grep -c 'pattern1\|pattern2\|pattern3\|pattern4\|pattern5\|...pattern14' This ...
1
vote
2answers
58 views

Using Grep Command Without Specifying a Certain Directory [closed]

Can you use the grep command without specifying a directory path afterwards? Example: $ sudo grep "filename" / I have also tried this: sudo find / -type f grep -l "filename" Still no luck. ...
1
vote
4answers
72 views

cat results of grep

I am trying to concatenate the results of my grep search. my grep search finds about 4 files on my system and outputs them in a new line for each file. I thought by passing this information to tr '\n' ...
0
votes
2answers
92 views

Using Both Grep and Cut

I want to grep the output of tcpdump and cut some part of it but the command below is not working. tcpdump ... | grep -i --line-buffered "..." | cut -d'&' -f1,2 Do you know what is the problem? ...
0
votes
3answers
65 views

highlighting parameters in with grep

I'm in need of some assistance with using the highlight feature in bash. My goal is to grep three parameters and then highlight them with three different colors. I've been messing around with this ...
3
votes
1answer
72 views

How to optimize 'grep'-and-save?

I want to know on which node my calculations were running on our cluster in case the node crashes and I get no files back to know on which node I have to search. For that case I wrote a little script ...
1
vote
1answer
37 views

List lines that consist of a single non-vowel character

I need help with listing lines that consist of a single non-vowel character. I got this: ls | grep -nv '[aeiouy]' file But this doesn't give me a single character. How do I get just a single ...
1
vote
2answers
78 views

List files that don't have certain letters in the first two character

I need help with listing filenames that are at least two characters long and don't have the following letters in the first two characters. The letters are abcfghxyz So far I have: ls | grep -v '^[...
3
votes
3answers
283 views

non-greedy grep

I want to grep a link from an external file example.txt. example.txt containins: (https://example.com/pathto/music.mp3)music.mp3 the code: egrep -o -m1 '(https)[^'\"]+.mp3' example.txt output: ...
4
votes
3answers
190 views

How to search efficiently for a list of strings in a big code directory

I have a list of strings, for every of those strings, I want to check if it occurs in a big source code directory. I came to a GNU grep solution that gives me what I want: for key in $(cat /tmp/...
4
votes
1answer
91 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
1
vote
1answer
47 views

How to test if certain strings existing in file are present in another file?

I have a file sites.txt that is generated by a script. It's a list of host names. I have another list of host names sites_old.txt. I need to check whether any of the host names present in the sites....
0
votes
3answers
36 views

Grep-like tool to show a specific region of a text relative to a pattern

I have this kind of text message published at a high frequency: pose: - position: x: 0.0 y: 0.0 z: 0.0 orientation: x: 0.0 y: 0.0 z: 0.0 w: 1.0 ...
1
vote
1answer
36 views

Why is there an error when grepping man results?

I am running this command, attempting to grep the output, but I keep receiving this error and I don't understand why. man man | grep color <standard input):977: warning [p 8, 0.8i, div '3tbd1,0'...
6
votes
4answers
374 views

How can I use grep to display lines WITHOUT either of two specific strings?

For a large logging file, how do I display those lines without "success" or not terminated with "ok"?
1
vote
3answers
86 views

How to add a different prefix to every line in a grep output?

I currently have this code: cat /proc/cpuinfo | grep "MHz" | cut -d ':' -f2 | sed 's/.*/Core NUM&Mhz/' Which outputs the following (for 8 cores): Core NUM 1941.054Mhz Core NUM 1949.820Mhz Core ...
2
votes
2answers
76 views

Grep only in files that are in certain folders

I want to grep for interesting string, but only in specific folder/file combinations, such as myfolder/myfile.out. The directory I'm grepping from may have these combinations in subdirectories of ...
0
votes
1answer
156 views

How to use negation of a command in a while loop with grep in shell script?

Is there any way to use while loop and grep all together? See my example: while [[ !(grep -R -h "${text}" ${path}) ]]; do ... done It says: ./test_script.sh: line 1: conditional binary ...
2
votes
2answers
52 views

How to find/grep what is between string1 and string2?

I am trying to extract a value from a long string that may change over time. So for example the string could look something like this ....../filename-1.9.0.3.tar.gz"<.... And what I want to ...
0
votes
1answer
34 views

Issue with grep, egrep in solaris

I have an issue when I execute this command in Solaris: grep -Ev "(^#|^EBM_SERVER|^$)" ${EBM_CONF} | awk -F, '{print $2"|"}' | tr -d "\n" | sed 's/|$//g' I got this error message: egrep:illegal ...
1
vote
2answers
71 views

How to use a greped url provided by tshark inside a bash script?

I'm trying to use a url piped from tshark into a while loop. while read line ; do echo "$line" ffmpeg -i "$line" -c copy "filename" done < <(tshark -i tun0 -B 50 -P -V -q -l -Y 'http matches "(...
0
votes
1answer
82 views

How to grep a string in multiple files on basis of month

I have a set of multiple log files and i want to search specific strings from those multiple log files between time period say July to October 2015. Please note there are multiple log files for each ...
0
votes
3answers
47 views

Extract Strings from Web Log file

Given a file containing web access logs for a YouTube video, every line is a hit and is in the format. 62.172.72.131 - - [02/Jan/2003:02:06:41 -0700] "GET /random/html/riaa_hacked/ HTTP/1.0" 200 ...
1
vote
0answers
21 views

Suppress warning of rbenv versions if no rubies installed

At the moment I'm working on Ansible role that installs ruby with rbenv. In order not to install same ruby version every time I run setup task I have to check that no needed ruby is already installed. ...
0
votes
3answers
59 views

Print lines after pattern in several files

I have a file with the same pattern several times. Something like: time 12:00 12:32 23:22 time 10:32 1:32 15:45 I want to print the lines after the pattern, in ...
3
votes
3answers
69 views

Can I grep two files against each other?

I want to grep file A for every phrase in file B, where a phrase is a string of words of length X. Ideally, it would be an approximate grep, like agrep. Is there a way to do that using command-line ...
2
votes
2answers
102 views

How do I ack-grep exclude file type *.sql files or file size larger than >3MB?

I want to search my directory for "foo" in the files, but i have these gigantic sql files. How do I exclude these file types or file sizes larger than 3MB using ack-grep? Also how would this be done ...
0
votes
2answers
41 views

Is there any tools that will let me check String length of XML Node

Am wondering if there are any tools that will do this: Exmaple XML: <node1> <Data> <Unique>123456789-1234567891</Unique> </Data> </node1> What i was hoping ...
3
votes
3answers
59 views

I want to grep out a text string from many files, how can I run a loop for this

I have a thousand .xyz files, all numerical data and in the same directory. Some of them have the text string "END" at the very end of them. I'm not sure how to loop a grep command so that it removes ...
1
vote
2answers
37 views

Egrep back referencing not working

I have trying top back reference the first captured group in the below command: $ ls -lR | egrep 'd(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))---' drwxr-...
-1
votes
3answers
52 views

Find files with the exception list of file name in separate file

I have 10 files in a directory.. test1.txt test2.txt test3.txt . . test10.txt Also a exclude file names exclude.txt which have the below file names test1.txt test2.txt test3.txt text4.txt I need ...
0
votes
0answers
60 views

Need some help on awk/grep command on shell script

This is in reference to Need some help on grep command on shell script I have a log file and I am trying to write a shell script to find pause/play happening or not (Success /Failure). The script ...
1
vote
3answers
33 views

How can I parse JSON to test the string value of a nested key?

For example, here is my program's output (bspwm, if you wanted to know): { "id": 29360131, "splitType": "vertical", "splitRatio": 0.5, "birthRotation": 90, "vacant": true, "sticky": false,...