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

learn more… | top users | synonyms

1
vote
2answers
56 views

How to use multiline as group-separator in grep?

In grep you can use --group-separator to write something in between group matches. This comes handy to make it clear what blocks do we have, especially when using -C X option to get context lines. $ ...
2
votes
1answer
37 views

Unset all ENV variables matching _PROXY

I'm trying to unset all environment variables that match _PROXY: env | grep -i _proxy | column -t -s '=' | awk '{ print $1 }' | grep -iv 'no_proxy' | xargs -0 -I variable unset variable but it's ...
2
votes
4answers
127 views

Change text in tag, but only tag is contained within a certain XML block

Using Git Bash, I'm trying to conditionally replace what's in the yrot tag in hundreds of files, but only if it belongs with a part name tag that pertains to wheel. // YES, change <part ...
5
votes
3answers
372 views

Why does this one-liner fail to produce output? [duplicate]

The following produces nothing in bash: while true ; do upower -d ; sleep 1 ; done | grep percentage | uniq I've discovered that it doesn't matter what the last- or even the second to last- program ...
1
vote
3answers
46 views

How to grep between words in a log?

I have a txt file with lines like below. Starting With: Parameters: {"raw_message"=>"MSH....... Ending With: </HL7Message>"} I'm wanting to grep and output to a file the words between ...
1
vote
1answer
192 views

“grep: memory exhausted” error on large partition

I was editing a text file with my notes on linux commands when I noticed a big chunk of it was missing (copy without paste, probably). The problem is that I already saved the document. (And this is a ...
1
vote
4answers
545 views

How to use regex to match a pattern which does not have a specific string at the end

How to use a posix bre or a posix ere regex to match a word which does not have bak at the end. I want to do a ls | egrep '<regex>' to find all files which DO NOT have bak at the end of ...
1
vote
1answer
44 views

Trying to find all files in certain directory that are not referenced in other files

I have this project that has a images folder with images in them and I'm pretty sure some of them are not used. So I'd like to list all images that are not referenced in any other file. I'm not very ...
4
votes
2answers
225 views

how to extract parts of file into separate files in linux using awk or grep or sed commands

I have text file as shown below: Input file1.txt ....................... cha21 1 3 5 nar cha21 2 3 6 piy cha23 2 3 5 ram cha23 3 ...
1
vote
2answers
104 views

How to filter content between specific keywords using grep?

I got a bunch of files, and I want to find out the content between two tags st and et. if I use grep "st.*et" files, I will get these two tags involved in the result. Such as st Hello world! et. But I ...
5
votes
8answers
1k views

How do I delete the first n lines and last line of a file using shell commands?

I have a file named Element_query containing the result of a query : SQL> select count (*) from element; [Output of the query which I want to keep in my file] SQL> spool off; I want to ...
2
votes
2answers
57 views

is it possible to search for files that have a special Linux file attribute?

is it possible to search file in the linux OS that have particular file attribute as this: ---S--l--- ---S--l--- 1 root root 0 Mar 1004:25/opt/csTuner/iba/wys/tuer_lolk What is S in ...
3
votes
1answer
46 views

Grep ignores part of my pattern?

I have a nice bash/zenity script that I use to check/update a number of git repos and report the status of each like this - showing only one sample repo here: zenity --class=CheckGit --info ...
1
vote
1answer
75 views

why grep does not print the entire line? [duplicate]

When I enter ls command I get the below output. -$ ls aNode ANode bNode BNode cNode CNode DUMP file1 hello.txt TEST.txt -$ As seen, above output is one line which has filenames separeted ...
1
vote
2answers
72 views

Count frequency of specific numbers in a text file of scientific notations

Background I have a text file, named blood_conc.txt as shown: 0, 0, 0, 0, 0, 0, 0, 1.32006590271e-05, 1.990014992001e-05, 1.504668143682e-05, 2.176900659261e-06, 7.673488970859e-06, ...
3
votes
4answers
254 views

Extract paragraph separated with *** using AWK

I have a file like below: blablabla blablabla *** thingsIwantToRead1 thingsIwantToRead2 thingsIwantToRead3 blablabla blablabla I want to extract the paragraph with thingsIwantToRead. When I had to ...
0
votes
2answers
23 views

Find a string between spaces

I was searching around the site and couldn't find a solution for the following, despite it's a simple thing. So let me share... If you know a better solution, please share I have the following log ...
0
votes
1answer
53 views

Copying files containing specific text preserving directory structure

Using the code in this answer, I can easily copy a file containing specific text from one folder to another. With the -r option I can also search inside directories recursively. The result is that ...
2
votes
4answers
223 views

Using Grep -o or Sed/Awk to Grab Snippet from Middle of String

I am watching log traffic and see regular abuse of the various image search engines, Bing particularly. Example URL: ...
3
votes
6answers
188 views

grep with continuation lines

How can I grep/awk/sed a file looking for some pattern, and print the entire line (including continuation lines if the matched line ends with \? File foo.txt contains: something whatever thisXXX ...
1
vote
2answers
52 views

searching for files with multiple strings (all inclusive, not one or the other ) and print line numbers

I want to search for 2 (or more) strings across the files of a certain directory and print the line numbers. The search results should include only those files where all the mentioned strings are ...
1
vote
4answers
1k views

Match exact string using grep

I have a text file: deiauk 1611516 afsdf 765 minkra 18415151 asdsf 4152 linkra sfsfdsfs sdfss 4555 deiauk1 sdfsfdsfs 1561 51 deiauk2 115151 5454 4 deiauk 1611516 afsdf ddfgfgd luktol1 4545 4 9 luktol ...
2
votes
1answer
75 views

grep misreads pattern from variable

I have a problem with escaped pattern put in grep. My test file is: export_cc = ${dir}/aaa/bbb/ccc export_cc = ${dir}/aaa/bbb/eee export_cc = ${dir}/aaa/bbb/ddd export_cc = ${dir}/aaa/bbb/fff ...
-1
votes
4answers
108 views

grep NOT maching exact string

I have a file 1 IF 9/1 Joe 2 IF 9/1 Marry 3 IF 9/12 Larry 4 IF 9/15 Page And I want to print only those lines that doesn't mach IF 9/1 using grep. I know that I could do that using grep -Fvx 'IF ...
1
vote
1answer
54 views

finding lines in a file matching patterns defined in another file

I have two files file1.txt kepaul jack mike david and file2.txt 1 london smith 12564 2 miami jack 51616 3 la mike 165156 4 london kepaul 54654 5 miami grag 46546 and I need to print to a new ...
0
votes
3answers
127 views

Find all words beginning with Q

How do I search a text file and list all the words begining with Q? The file I am searching is Python source code. The closest I have found to a soulution is this question but that is not what I ...
-4
votes
2answers
56 views

Displaying a list of all *.java

Display a list of all java files which name is *.java in your current working directory which contain the string Example, regardless of the case sensitivity of the latter's individuals letters. ...
4
votes
6answers
200 views

Append something to each list in a file

I have a file, lists.txt, that looks like this: // stuff at beginning of file var list1 = new Array(); i = 0; list1[i++] = 'a'; list1[i++] = 'b'; ... list1[i++] = 'z'; var list2 = new Array(); i = ...
2
votes
1answer
179 views

How to grep whitespace exclude new-line character?

Today I need to check which lines of my files containing trailing whitespace. And I figured out a solution: grep -Enr --color "\s+$" ./ This works well except for those lines containing non-Unix ...
1
vote
0answers
19 views

Interpreting regex wildcards with grep [duplicate]

This is a really simple question, but even after reading about wildcards/regex, I can't seem to grasp entirely what the differences between these commands are: grep . test.txt this one will look ...
0
votes
1answer
55 views

grep to compare files not working

I successfully used: grep -wFf inputqueries.txt seachedfile.txt > results.txt to search searchedfile.txt for each query in inputqueries.txt. inputqueries.txt looks like: 213.183.56.186 ...
2
votes
1answer
400 views

What does this grep expression mean? [closed]

\*.\?[A-Z]\?.* This grep command is cryptic. I understand that it is supposed to search for uppercase commands.
5
votes
5answers
451 views

Run `grep` excluding a file in a specific path

I want to exclude the file ./test/main.cpp from my search. Here's what I'm seeing: $ grep -r pattern --exclude=./test/main.cpp ./test/main.cpp:pattern ./lib/main.cpp:pattern ./src/main.cpp:pattern ...
1
vote
1answer
41 views

Get `grep` to not output file name

When I use grep -o to search in multiple files, it outputs each result prefixed with the file name. How can I prevent this prefix? I want the results without the file names.
4
votes
3answers
362 views

Extracting unique piece of text from file with awk, sed or grep

From the output of pactl list sink-inputs, I need to grab the sink input number for VLC. Before that, I'm trying to extract the piece that contains the output for only VLC. All the methods that I ...
1
vote
2answers
114 views

Extract some columns from grep output

I've run the command grep -a --binary-file=text "DLDM" /home/path/ldm.log-$1* | grep -a "$line" and the output is something like this :- /home/path/ldm.log2015:"unix","20150518 ...
5
votes
2answers
371 views

How to search for text in a file ignoring newlines?

I'd like to search for text that may be split over several lines in a file. A grep that would ignore line breaks and return the matching span of lines. e.g. I would be searching for is an example ...
1
vote
1answer
222 views

what is meant by “^$1” in shell script?

#!/bin/sh #emp3.sh: using if and else # if grep "^$1" /etc/passwd 2>dev/null then echo "pattern found - job over" else echo "pattern not found" fi in the above programme what is "^$1" and ...
0
votes
1answer
53 views

grep searching groups

I'm trying to learn to use grep groups, like sed \1\2\3, but have a problem. For example I filtering /etc/services file to separate all ports. What I do: ~$ grep -E '[0-9]{1,5}/(tcp|udp)' ...
1
vote
2answers
76 views

How to perform grep on 'man unix_command'?

Often while going through the output of man man awk I Need to perform grep, for e.g. in man awk, I need to find the definition of a particular flag, variable etc. Can anyone tell me, what would be ...
4
votes
1answer
157 views

What is the opposite of “grep”?

Say I'm printing out a long series of strings, and instead of only showing lines containing a certain pattern (which one uses "grep" to do), how do I filter out certain patterns?
-1
votes
1answer
27 views

Grepping entire system but dodging process files and the like [duplicate]

I have so many systems I need to do and I find it really impractical for me to grep everything/folders individually.
2
votes
2answers
59 views

Can't get GNU grep 2.12 to handle LF character in regex expression

I've been at it for over an hour, but can't find why it's not working. I'm searching an HTML document for "\nSome text". Simple enough. But he following commands won't work: grep -Po ...
1
vote
0answers
92 views

Grepping multiple instances of a string, with context, from a file

I have a MySQL dump file, which is mostly INSERT statements. I want to grep out instances of the string 'media' from a field in a particular table, with +/- ~10 characters of context. The string might ...
1
vote
5answers
73 views

Grep 2 different requirements in one command line statement

How would I print the last 3 lines that have the string #include from tester.c and if fewer than 3 lines contain the string, print the entire file. So far I have: grep "#include" tester.c | tail -3 ...
1
vote
1answer
44 views

Conditional awk across 4 columns

I have a tab-delimited file with 9 columns as follows: 1 25555818 T 14 0 0 0 14 0:0:0:14 2 25555819 T 14 7 0 0 7 7:0:0:7 3 25555820 G 13 0 0 13 0 ...
2
votes
4answers
409 views

Wildcards for filepaths aren't working in grep [duplicate]

I need to grep words like these: ABC-DEF AB2-DEF AB3-DEF AB-DEF So I was trying: grep AB*-DEF grep -w -AB*-DEF grep -w AB*DEF But neither of them are working. Please help.
-3
votes
1answer
50 views

grep-ing - I think [closed]

I have a multitude of files (2TB) which all have word data in them. All the data follows the same format but the information slightly changes I need to be able to pull out specific data from the files ...
2
votes
2answers
140 views

Extract substrings from each line. These substrings are in comma separated, “name=value” format

I have lines in a file that are comma separated. There are no column headers, it's mostly comma separated 'name=value' pairs. Here is some test data: ...
2
votes
3answers
58 views

Search a String in a directory- Get output without filename

I am executing the below command to display the lines which matches the pattern. find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507" And output is ...