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

learn more… | top users | synonyms

0
votes
0answers
43 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
2answers
94 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
414 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
50 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
96 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
44 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
52 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. [request://Problem/...
0
votes
2answers
33 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
61 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
56 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
183 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
140 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
40 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
25 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
63 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
65 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
67 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 ...
1
vote
1answer
45 views

Why “grep -q -v” only works with single line input?

If I use grep -q in combination with -v to return 0 if there are no matches or 1 if there is a match, it works as long as input is a single line: $ echo 'abc' | grep -q -v a; echo $? 1 $ echo 'abc' | ...
0
votes
1answer
65 views

replace long text string (script with MANY special characters). sed, awk, grep

My site was hacked / infected. I replaced the url of the malicious link, but other elements in the malicious script are still making my site get blocked. Without inserting a hundred or so "escapes", ...
0
votes
2answers
40 views

Retrieve string between two strings

I'm trying to extract a substring in the middle of two strings. I execute this grep command: echo "http://www.miweb.es/midoc-87-documento-texto_mf_4150310_1.txt" | grep -Po "(?<=midoc-).*(?=-)" ...
0
votes
4answers
62 views

Grep for a string and then echo a string back from a record

I have the following record: MiraServ.log.10:2016/02/07 15:25:13 3 All stations busy!! MiraServ.log.10:2016/02/07 15:25:13 1 TranHasError (3627,-2) EDxxxxxxxxxxxxxxx,MI1,IN0019093203,A113214,TK00:...
0
votes
1answer
30 views

Remove file name when recursively counting number of occurrences of a pattern

When I run my grep command: grep -rc 'PATTERN' . it prints out the number of lines that the pattern occurs, but it looks like this: ./hotel_232424.dat:234 and so on... How would I remove the ./...
0
votes
3answers
227 views

Filtering content from df output

I have the command below to get the filesystem usage on a server: df -k | awk '{print $5 " " $6}' | grep % When executed, the following are the results: 97% / 0% /proc 0% /etc/mnttab 0% /dev/fd 46%...
3
votes
2answers
157 views

Is there a way I can grep recursively over all the files in the current directory to find a pattern and then print it in order of high to low?

So so far, the code looks like this: grep -rc 'Author' $1 It prints out all the files in the directory, which is taken as an argument. However, how would I sort the output (for example): - data1:...
0
votes
3answers
39 views

List out the original IP Address of the host

I have following content in the file. I would like to print the IP address which is Under Name. Server: 17.128.100.12 Address: 17.128.100.12#53 Name: Testserver1 Address: 17.146.118.156 ...
3
votes
1answer
111 views

Print some lines before and after pattern match excluding lines matching another patterns

I use awk on Solaris to print 5 lines before and after a pattern match. Currently, the following one-liner does the job: /usr/xpg4/bin/awk 'c-->0;$0~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+1)%b];...
3
votes
1answer
38 views

grep output of cdrecord

I would like to parse the output of cdrecord/wodim using grep. cdrecord -v outputs lines like Track 01: 49 of 75 MB written (fifo 100%) [buf 100%] 10.2x. The problem is that cdrecord uses ...
1
vote
3answers
134 views

Finding and removing words beginning / ending with numbers

I have a large file (>10000 lines) that contains one word per line, with a newline character after each word. The words contain no spaces. I'd like to list (or even better, output to a new file) any ...
-2
votes
2answers
34 views

Grep contains 'this' but can't contain 'this' into a file

I'm currently working on a homework assignment and it is basically saying, "Find the single line with "Ju" but does not contain the letter "w" in that line" I believe that I have to use grep. However ...
-1
votes
3answers
73 views

Using grep to remove comments from a file

I'm trying to use grep to remove the comments from a file, smb.conf to be specific, and bash is giving me an error. I found this question How to remove all comments from a file? that gives the syntax ...
0
votes
3answers
50 views

How to search multiple Pattern in grep while ignoring the first pattern if appearing consecutively

I have an input like below. I want to find out everything starting with abc and ending with mno including lines in between but if abc appears again before mno comes, then I want to ignore the first ...
1
vote
3answers
46 views

How do I search a directory of data files and print out how many times a certain word appears in each file?

This is what I currently have, however it prints the total number of times Author appears in all of the files: 128367 grep -roh 'Author' $1 | wc -w However how do I print out the word count for ...
1
vote
1answer
69 views

Combining strings command and grep: how to limit results to null-terminated strings

I have a feeling that it is strings which is thwarting my efforts here. The binary files I want to use strings on unfortunately yield several matches per file, even though it is a 100% rule that ...
2
votes
4answers
686 views

The wc -w command outputs incorrect answer [duplicate]

I have to find how many times the word shell is used in a file. I used grep "shell" test.txt | wc -w in order to count how many times that word has been used, but the result comes out 4 instead of 3. ...
0
votes
1answer
64 views

delete line that contains a case insensitive match

I have a file that contains information as so: 20 BaDDOg 31 baddog 42 badCAT 43 goodDoG 44 GOODcAT and I want to delete all lines that contain the word dog. This is my desired output:...
-2
votes
2answers
77 views

linux on aix dont work pgrep -lf ora_pmon

pgrep -lf ora_pmon ksh: pgrep: not found. somebody know who to change the code without pgrep this is the result on another Os pgrep -lf ora_pmon 4104 ora_pmon_dbpicsr 5092 ora_pmon_dbpiss2r 14393 ...
1
vote
1answer
43 views

Linux + capture only the IP's from mount command

please advise how I can to print only the list of the IP's ( in the end of the lines ) , from mount output mount netapp64:/lunggg/OracleTeam/OracleCDs on /oracds type nfs (rw,fg,hard,nointr,nolock,...
1
vote
5answers
779 views

Grep value from json file

my json file looks something like this [{"product":"Apple","id":"2134"},{"product":"Mango","id":"4567"}] I want to grep/sed/awk 'id' for given 'product'. Output: Enter product : Apple Your ...
0
votes
0answers
45 views

Unix scripting : Writing to another file with “:” is failing

I have below record (and many other such records) in one file 9460 xyz abc (lmn):1027739543798. Taxpayer's identification number (INN): 123. For all IIB. 2016/02/03 I need to search ...
1
vote
2answers
55 views

grep to search error_log and email only when results found?

Is it possible to use Grep to search a file and send a email based on the results? I have been using grep SEARCHSTRING /logs/error_log | mailx -s subject name@emailaddress.co.uk But I don't want ...
2
votes
1answer
26 views

grep awk or sed a CSV Row containing a certain part of a web address

I am trying to clean up a Squid log file and I want to delete rows with a website containing "/0/" in the 11th column. An example: Row1: column1, column2, column3...column10, ht*p://blah.com/page/230/...
0
votes
4answers
77 views

grep match multiple substrings and pass or fail on missing

I have a nginx -V 2>&1 | \ grep -qi 'nginx/1.9.10\|ngx_pagespeed-release-1.9.32.10\|openssl-1.0.2f\|modsecurity-2.9.‌​0' \ && echo "has the stuff we need" \ || echo "missing something"...
2
votes
5answers
568 views

ls | grep works doesn't work with ls --color

I'm trying to list all hidden dirs with the following command ls -lhAF1 | grep -E '^d.*[0-9]{2}:[0-9]{2} \.' which works perfectly fine Explanation for Regex: I'm trying to get all rows that ...
0
votes
4answers
77 views

Run multiple piped grep commands from a list in bash

As part of my security job, I analyze dozens of Google Chrome history files each day using sqlite3 over SSH. There are a few dozen authorized "safe" sites each user is allowed to navigate to. For my ...
3
votes
3answers
140 views

Retrieving lines from a file depending on other lines

Imagine the following file structure: foo.bar.1 blabla moreblabla relevant=yes foo.bar.2 relevant=no foo.bar.3 blablabla foo.bar.4 relevant=yes I want to retrieve all foo.bar lines where within the ...
0
votes
1answer
87 views

How do I grep the lines based on '.' (dot)? [duplicate]

Suppose I've file with the following contents: 123 251 7.8 951 Now I want to grep the lines having . I've tried: $ cat file | grep . 123 251 7.8 951 $ cat file | grep '.' 123 251 7.8 951 But ...
0
votes
1answer
26 views

grep -E with parameter doesn't work

If I use -E option for grep from a script I'm unable to user variables. For example: txt file: word nir asd b asd text script: #!/bin/bash PARAM=b cat txt | grep -E 'nir.*${PARAM}' The script ...
-1
votes
2answers
40 views

Grep expression with spaces - BASH

I would like to grep ACCEPT, DROP, REJECT as is shown below. -P INPUT ACCEPT -P OUTPUT DROP -P FORWARD REJECT I executed iptables -S | grep -E '\-P INPUT|\-P OUTPUT|\-P FORWARD' | awk '{print $2}' ...
0
votes
1answer
53 views

Why does piping filenames into VIM break bash when I return to the shell?

I searched for a few files with find and I wanted to open all of them in tabs in Vim. So I tried this: find . | xargs fgrep -l myExpression | xargs vim -p This worked great, except when I was done ...
0
votes
2answers
121 views

What does this command mean?

lines=$(grep '^[^:]\+::' /etc /shadow) What does this whole command mean? What does '^[^:]\+::' mean? if I put if else statement like: if [ "$lines" == "" ]; then Will it display (which is ...