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

learn more… | top users | synonyms

4
votes
3answers
159 views

egrep regular expression for times over five minutes

I have the following time formats in a text file `1` equals one second. `5|01` equals five minutes and one seconds. `13|01` equals thirteen minutes and one seconds. `21|12|01` equals 21 ...
2
votes
2answers
88 views

how to grep specific string in random column

I'm looking to find out any farmer who produces bananas and his address from a database. My data looks something like this: - farmer1 address1 apple1,banana-green,orange-5 - farmer2 address2 ...
0
votes
2answers
35 views

Search string using grep

In my file_*.txt there are two type of words one containing LC1 only and another containing LC1_R. I would like to grep lines that contain only LC1 not LC1_R. How can I do it? I tried: grep "LC1" ...
4
votes
3answers
254 views

grep regular expression solution (greedy not working)

I have the following text in the data.txt file :MENU1 0. public 1. admin 2. webmail :SYNTAX ! opt1, ... : :ERROR1 Error #1, blah... blah.. blah... Please do ... :ERROR2 Error #2 ... and I want ...
2
votes
4answers
148 views

Grepping pieces of a string to form a new string

I am parsing some log files and have grepped out the errors. Each line looks something like this: CreateOrder_hostname1.domain.com_201509291530_tee.log:2015-09-29 15:42:06,715:ERROR :Thread-...
0
votes
2answers
103 views

Grep string then delete word and do next statement

I want to create bash shell script which can - find string in file - then delete word - then restart service I have tried this code Restart.sh #!/bin/sh grep -q 'RestartServiceApache' /srv/...
0
votes
1answer
86 views

Match everything after backslash and before space

I have strings similar to the following: *unknown*\*unknown* (8) hello\morning (3) I'm trying to match just morning or *unknown\*. So far I have tried: [^\\]+$ But that matches from backslash ...
0
votes
3answers
942 views

How to grep for two words with a tab in between them

I've got a file with with a list of words each delimited by tabs. I'm trying to use grep to search for two of the words, but I can't figure out how to include the tab in the search string. I've tried: ...
-3
votes
1answer
122 views

Regular expression: when every alternate character is a digit

I am trying to write a Linux command using egrep that validates lines whose even character is a number. I am doing it this way: egrep "^(.[0-9])*$" text.txt However, this fails for i) empty ...
0
votes
1answer
345 views

How do I find block of text, from a text file, containing a specific string [duplicate]

I've been looking to extract a block of text, from a text file, containing a string with no success. Any help would be really appreciated. For example: I have a file named xyz with below contents: ...
0
votes
2answers
37 views

Looking for files ONLY in subdirectory

So let's say I want to search for files that are C files. How do I go about searching for them ONLY in my sub-directories? I tried: ls -R | egrep .c$, but that also searches for .c files in my ...
0
votes
3answers
71 views

Words that end with s BUT exclude words that end with 's

I need to find a list of 5 letter words beginning with d(upper or lower case) , followed by a lowercase vowel including y and end with s. My command: grep -i '^d[aeiouy]....s$' file name. I want to ...
1
vote
3answers
101 views

How to grep for a word taking into account hyphenation?

For the purpose of building an index I am searching for some words in a bunch of latex files. This process is complicated by the fact that latex has a discretionary hyphen command \-, which indicates ...
5
votes
3answers
248 views

Search for a precise number with grep

I am trying to look for lines in a file that have one or more instances of 1234, but no other numbers (non-digit characters are allowed). Any other number should cause the line not to match. Valid ...
3
votes
1answer
183 views

How to use grep with files in arbitrary encoding, without locale installed and without sudo?

I have utf-8 locale on my computer, and i want to search in KOI8-R encoded files. But i don't have KOI8-R locale installed. And i don't have sudo rights to install this locale. Is it possible to ...
0
votes
2answers
103 views

How to find lines in file containing set of special characters?

I am writing a script that runs through an existing c program and finds whether it contains comments: They should start and end in comment tags: /* and */ How can I achieve this? Example: This ...
0
votes
1answer
18 views

Is there a way to get all the NEWS.gz which is/was this year in /usr/share/doc/ of $PACKAGENAME

If people go into /usr/share/doc/$PACKAGENAME (you can use any valid package name which you have installed on your system) you will see that the directory has various files in it, at the very least ...
1
vote
3answers
142 views

bash: grepping contents of column which is dynamic

I have data as following : What i need to get is the OS_NATIVE_NAME of a particular DEVICE. I know one way is to print its column value using: awk '{print $*col_num*}' But the column number ...
0
votes
2answers
67 views

Grep for string but ignore commented out items with string

I'm looking for the words gmail or outlook in a directory. Although there are some lines commented out with the word gmail and outlook in it. How can I grep for this? I tried a bunch of things but I ...
-1
votes
4answers
187 views

How to grep AND pattern with pipe

I wrote a piece of script similar to something below: srvc_location=`ps -ef| grep '${sandbox}.*pset' | head 1 | awk {print $9}` echo "SERVICE LOC : "$srvc_location But strangely this $srvc_location ...
3
votes
4answers
237 views

Bash script condition always passing even when grep should return nothing

I am having issues when trying to return the one image file that fits the parameters. $1 is the search parameter, in this incident it is "real" which is a tag on one of the images (not two) in the ...
0
votes
3answers
288 views

How to extract a particular value from log file and transfer it to another file

I have a log file which looks like: ########### mv90_poll.sh started Wed Sep 23 02:36:00 PDT 2015 ############ /usr/mv90/mv90/system/*.di not found list *.HHF files in /usr/mv90/fats -rw------- 1 ...
2
votes
2answers
103 views

Identify sub-directories that do not contain a specific string in a specific file

I have a directory named dir1 which has about 800 sub-directories named disp-001, disp-002, ... disp-800. I need to find sub-directories that either do not contain a file stdout or if they do, that ...
3
votes
1answer
111 views

Find words with the same vowel separated with a consonant

I'm looking for a grep argument to find in a text words that have the pattern vowel-consonant-samevowel. Examples: oro enero fofo ppppepepppp Thanks.
1
vote
1answer
141 views

Including or in grep pattern

I want to grep a word wrap in single quote or double quote eg. "myWord" 'myWord' I am using grep -rn "\"\|\'myWord\'\|\"" this should allow "myWord" , 'myWord" , "myWord' and 'myWord' , but ...
6
votes
4answers
346 views

Count number of a substring repetition in a string

I have a file which contains a gene sequence such as: ...
1
vote
3answers
77 views

Search a file for lines NOT containing a phrase with context

I have a file with many entries consisting of a keyword followed by several lines of numbers. I want to filter out one category of entries, so if entry derp is followed by three lines I want ...
4
votes
2answers
272 views

split a large file to new file with unique file names

I need to split a file into unique file names. I can do it with sed command eg, sed -n '/scaffold135_/w 135-scaf.txt' input file.txt but it's time consuming so I need a smart way to do it faster. ...
1
vote
1answer
484 views

Conditional Check for IPTables

I am trying to check whether specific rules in IPTables exists or not. #!/bin/bash if iptables -L -n | grep -- "ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8880"; then ...
0
votes
1answer
102 views

grep: memory exhausted on big file when using pipe [duplicate]

When I try to find a specific byte with grep not using pipe I get some output: $ grep -aboP "\\x55" bigfile 510:U 1049086:U 1049598:U But when a pattern is supplied via pipe then there is a memory ...
5
votes
3answers
115 views

How does grep decide that a file is binary?

I have a large utf-8 text file which I frequently search with grep. Recently grep began reporting that it was a binary file. I can continue to search it with grep -a, but I was wondering what change ...
1
vote
3answers
124 views

Grep for multiple strings, show number of lines after one of the strings (but not the other)

As the title suggests, I would like to search a file for multiple strings and for one particular string, show the 5 lines following it as well. cat file | grep -e 'string1' -e 'string2' works of ...
1
vote
2answers
166 views

How to remove a line from a tag in shell script?

We have an xml file (abc_lop.xml) in which I need to remove a line which is present in a tag: Below is an xml file, I have shorten it down as it is very big. <HELLO version="4.2" xmlns="http://...
-1
votes
1answer
37 views

Get the respective tablenames if it matches particular pattern

I need to list the table names if it finds particular pattern from the below file. CREATE TABLE IMS.ACTIVITY ( "ID" INTEGER NOT NULL , OWNING_TYPE FOR COLUMN OWNIN00001 VARCHAR(20) ...
1
vote
3answers
271 views

how to extract a value from a string in xml using grep or awk in Linux

I have a file containing: DEVICE="7" PGMNR="24" VCONF="800" In this file, I want to find PGMNR="24" and I need the value 24 without the ". The PGMNR="24" may be located anywhere in the line. The ...
0
votes
0answers
29 views

grep names from big list and sort it according to pattern [duplicate]

I have 2 big files as shown below. I want to read the pattern file and grep the line from full-info file and sort the channel name order according to pattern. pattern file HBO COMEDY; DTV CABLE ...
2
votes
1answer
123 views

In bash, grep for a line beginning with \, and assign the result using backticks

In bash, I'm trying to grep a file for a line beginning with a \, and return the result using backticks. For example: echo \\Hello > myFile out=`cat myFile | grep '^\\Hello'` echo $out returns ...
1
vote
1answer
179 views

Figure out the PID of exact node.js application

Here is an output of my ps aux: ps aux | grep "node" root 2501 0.0 3.4 720400 68512 ? Sl 16:09 0:03 node /etc/skbx/host/skbx.js 8081 tula13 8082 8084 8085 10.8.0.6 root 20586 0....
-1
votes
2answers
64 views

passing all the contents of a file as keywords after grep command [duplicate]

Suppose I have two files named a.txt and b.txt. Is there any way to use all the contents of file a.txt to use as patterns for grep command if I want to search in file b.txt? General format of grep ...
1
vote
1answer
77 views

grep -E regex syntax changed?

A lot of documentation I've read says that the following command should match lines where x appears at least 3 times in a row but no more than 4 times in a row: grep -E {x}\{3,4} E.g. http://www....
0
votes
1answer
61 views

grep a pattern that doesn't have dot after it

File a contains, abcd abcd. defgh defghabcd. defgh. abcd abcd .defgh How can i print all the lines that has the pattern abcd without a dot suffix? It must print, abcd defgh. abcd abcd .defgh #. ...
0
votes
1answer
104 views

Modifying the search result of grep

Normally, we can search a keyword in a list of pdf files using the following command: for file in *pdf; do pdftotext "$file" - | grep keyword done Now, from the search result, If I want to find ...
2
votes
3answers
109 views

Searching a keyword in multiple pdf files

I want to search for a specific keyword in multiple pdf file using pdftotext command. Normally we can search inside a single pdf file using the following command: pdftotext file.pdf - | grep keyword ...
4
votes
1answer
379 views

Match pattern \\\" using grep

I have a json string inside json. This got encoded multiple times and I ended up with many escape backlashes: \\\". The much shortened string looks like, '[{"testId" : "12345", "message": "\\\"the ...
0
votes
1answer
57 views

Fetch second and fourth column from a file

Problem Statement I am not able to get the values in second and fourth column. Tried grep -i "AUGC\|AACN\|AACY" output.csv | cut -d ',' 2,4 DATA success,1234,["madhu",{'first',[{'last',18}]},"I0"...
-1
votes
1answer
64 views

Grep command to output in file

grep -irm 1 "some_pattern" . | wc -l > myfile.txt I used this command to find out the number of files having the given pattern. I want to output it in file. But I couldn't... what to add or ...
2
votes
1answer
113 views

Double square parenthese inside grep pattern

grep "^[[:space:]]*clientPort[^[:alpha:]]" zoo.cfg This is a grep pattern to extract the line that contains the port number from the configuration file. 1) Normally in a regex, I use square ...
1
vote
3answers
86 views

How to search multiple search patterns from a file with grep

If I search for multiple search strings in grep : usually just do: grep "search1\|search2" somefolder/*.txt but, what if I have 100 or more search strings? Can I say like this: grep "stringPattern....
0
votes
2answers
48 views

Bash script to copy specific directories with pattern matching

How can I copy directories from one location to another location that matches a pattern. For example: source = /media/src/ destination = /media/dest/ The pattern is as /b/w{2}_/w{2}/b. i.e all ...
0
votes
1answer
95 views

Need to capture part of file name into variable

I have bunch of CSV files named like so in a directory: s_m_u_supplemental_fields_account_9_4_2015_11_26_Error.csv s_m_u_supplemental_fields_account_9_4_2015_12_3_Error.csv ...