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

learn more… | top users | synonyms

0
votes
2answers
68 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
55 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
70 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
34 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
75 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
272 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
185 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 ...
3
votes
1answer
87 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
44 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 ...
0
votes
3answers
29 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
34 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 ...
6
votes
4answers
365 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
65 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
61 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
78 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
41 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
27 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
61 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
59 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
34 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
15 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
57 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
60 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
64 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
34 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
53 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
36 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))---' ...
-1
votes
3answers
40 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
59 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
31 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": ...
-2
votes
2answers
54 views

Listing lines that start with a number and end in a sequence [closed]

So basically, I need help with listing lines with their line numbers that contain one or more words that start with 42 and end in a sequence of any number (but not zero) of character X. so far what I ...
0
votes
2answers
43 views

Shell output from one command as input to other

I am trying to automate Forever JS to keep my dev server running and for that I need to check and stop the forever process to start another one. By running sudo forever list I get the following ...
2
votes
2answers
63 views

Print lines of a file between two matching patterns [duplicate]

How can I print all the lines between two lines starting with one pattern for the first line and ending with another pattern for the last line? Update I guess it was a mistake to mention that this ...
0
votes
0answers
39 views

Standard deviation of number next to a pattern

I have a file with lots of tags with a number next to them, set out like this: <Score>4 ... other data <Score>2 ... other data <Score>3 and so on... I have used grep to get the ...
0
votes
1answer
71 views

parse HTML in Bash (when grep just isn't enough)

This is driving me insane, as I'm sure there must be some program doing the job but I just can't find it. To be noted, I'd be on ARM/Raspberry so unfortunately Xidel is not an option here, unless ...
2
votes
7answers
312 views

grep ignores files starting with dot [duplicate]

Let me give an example: $ echo Hello > file1 $ echo Hello > file2 $ echo Hello > .file3 $ grep Hello * 2>/dev/null file1:Hello file2:Hello Here you can see the grep ignored .file3 which ...
0
votes
1answer
46 views

Grep: Why escape modifiers?

By modifiers I mean the following: -\{m\} exactly m repetitions of previous character - \{m,\} at least m repetitions of previous character - \{m,n\} any number of repetitions of prev char between m ...
3
votes
2answers
77 views

Find each line matching a pattern but print only the line above it

I need to find a string and need to print the line above it. case1: The same line won't have the more than one matching pattern ie) consider a file containing $cat > para returns between the ...
1
vote
2answers
39 views

what command would I use to see all lines from a file starting with a line that I find with grep

what command would I use to see all lines from a file starting with a line that I find with grep so I imagine something like a tail, but beginning from a line that I identify with a grep. For ...
-3
votes
4answers
51 views

How to print only the ticket numbers?

Following is the content of the file and i need to print only the ticket numbers which are enclosed in "[]". Curious to know if this can be done using both sed and grep commands. ...
0
votes
2answers
32 views

Counting the occurences of character in a filesystem tree

The task was to find the number of occurrences of character 'a' in all files in the directory (recursively). My script was this find . -type f -exec grep -o 'a' {} \; 2>/dev/null | wc -l but it ...
1
vote
2answers
56 views

Why does perl regex find pattern \\label\{.*?\} but not \\ref.*?\} or \\autoref\{.*?\} in TeX Files?

I am using perl to parse many multilingual text files. I need to change the text between two patterns: Desired Changes For example, the English original version looks like this: \label{whatever} ...
2
votes
1answer
49 views

Redirecting looped grep commands to separate files

I'd like to use grep to recursively search through a directory, using patterns listed in a file, then store each result in its own file for reference later. I'm a complete novice at bash scripting, ...
3
votes
1answer
84 views

Grep is not matching non-ascii characters

I found a problematic sequence of a supposedly UTF-8 encoded text file. The strange thing is that grep seems unable to match this non-ASCII line. $ iconv -f utf8 -t iso88591 corrupt_part.txt --output ...
1
vote
2answers
104 views

Grep line after/before -A/-B substitution in AIX

I'm using AIX 6.1 which isn't supporting in -B and -A flags: grep: Not a recognized flag: B Lets say I want to run: cat file | grep -E -B4 'Directory entry type.*Indirect' | grep "Database name" | ...
-1
votes
1answer
39 views

Write a program that finds a phrase and print out

I need help with writing a shell program that finds the phrase "Candy Land" and prints out the 10 lines surrounding the line where that word is found. Assume it is only found once. I don't know what ...
0
votes
1answer
23 views

Piping difference of grep -c's with different regex to bc

I need to find the number of words in a file (1 word per line) that do not contain some set of letters. To do this I want to take the difference of grep -c '.' <file> and grep -c ...
1
vote
1answer
57 views

Search a string in files in the current directory, omit duplicates

Assuming I want to write a line which prints out lines which match a specific string without repeating duplicate lines .. I want to search for this string in the files of the current directory: grep ...
1
vote
2answers
47 views

How to reverse sort the output from grep -rc

I want to be able to sort the output from the grep -rc command, I am currently using the command: grep -rc "Pattern" . | sort -t: -rk2,2n however the list is still sorted from low to high, ...
3
votes
2answers
54 views

How can I do a binary search of a text file for a specific character string?

I have a text file that contains a large number of records, each on a single line. Some of the records have special characters that have been corrupted, and I'm attempting to find those by looking for ...