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

learn more… | top users | synonyms

6
votes
4answers
143 views

How to grep-inverse-match and exclude “after” and “before” lines

Consider a text file with the following entries: aaa bbb ccc ddd eee fff ggg hhh iii Given a pattern (e.g. fff), I would like to grep the file above to get in the output: everything except ...
4
votes
1answer
47 views

How can I repair a tar file where stderr got mixed with stdout?

I have a tar file that I'm trying to repair. The problem is that tar's stderr got mixed in with its stdout, so the file looks like this: % head android-1435613730.tar tar: removing leading '/' from ...
-1
votes
1answer
43 views

To sed if with and without conditions correct

I know that I may have the C package #include <stdint.h> in the first 1-30 lines. I would like to add it to lines where no previously if the file contains the word LARGE_INTEGER by GNU tools. ...
3
votes
2answers
51 views

How do I filter stdout of a program through grep while still controlling the program?

I'm trying to filter the output of the mpv media player, removing a particular line, but when I do so I am unable to control mpv with the keyboard. Here is the command: mpv FILE | grep -v 'Error ...
2
votes
3answers
95 views

Split binary data of fixed byte offset by byte position?

I have binary data which I review by xxd -ps in hex format. I notice that the byte distance is 48300 (=805*60) bytes between two headers where the separator is fafafafa. There is the beginning of ...
2
votes
1answer
18 views

Extract values from block of data

I have the below block of data. Heap after GC invocations=31 (full 3): par new generation total 131008K, used 0K [0x00000000eac00000, 0x00000000f2c00000, 0x00000000f2c00000) eden space ...
9
votes
5answers
511 views

How can I count the number of lines in a file after a grep match?

I am trying to count the number of lines after a problematic row in a csv file. I am aware I can use the grep -a # syntax to output # number of lines after a match has been found. I'm only interested ...
1
vote
2answers
53 views

How do i search for certain sections of a file and then extract only relevant information within that section?

So I have a text file that is a server report and has about 1000 lines of information in it. I'm trying to write a script that can search the report for only certain pieces of information I'm looking ...
1
vote
2answers
49 views

Search for a multiple patterns in specific column in fixed length file and output entire line

I need a command in Unix to look for a pattern in specific columns in a fixed length file and output the entire line to a different file. Example File1 2345abcdef450022677 1234sdfght350022677 ...
0
votes
1answer
38 views

Delete email addresses in .csv that are listed in a .txt file

I run the following command to keep email addresses listed in emails.txt grep -wFf emails.txt file.csv > newfile.csv But how would I change this command to remove addresses from file.csv that ...
2
votes
1answer
67 views

Match a number range with grep

I need to find all processes that have in their names a number between 100 and 200 inclusive. I tried ps -ef | grep xclock -bw '[1-2][0-9][0-9]' but that includes 299. How to suppress it and ...
1
vote
1answer
33 views

Obtaining unique lines with matching strings [duplicate]

I have a JSON like text file of records with duplicate ids that look like: {"ID":"93" , "ST":[42,77,51]} {"ID":"21" , "ST":[43,4]} {"ID":"94" , "ST":[65,11,4]} {"ID":"93" , "ST":[42,77,51,29,63]} ...
1
vote
1answer
33 views

Is my understanding correct about egrep -if file1 file2?

I am using KSH, Solaris 5.10. Suppose file1 contains a list of fruits and file2 contains list of fruits & nuts. My understanding about the following command egrep -if file1 file2 is that it ...
0
votes
2answers
43 views

Grep for regex in basename but return wholename

So say I have a list of files in a text file: ... /foo/barfoo /bar/foo/foobar /foobar/bar/foo ... I have a script that will search through this text file and, much like the locate command, I want ...
-2
votes
1answer
40 views

How to get more than 20 lines of output with grep when searching for a string with spaces [closed]

I am currently using grep like this: grep search_string search_file > output_file Here is an example: grep "ich arbeite" deu.txt > out.txt When used in this way, I only get the last 20 ...
1
vote
4answers
46 views

Find text in a file and copy it to another file

Is there any command in Linux to find text in a file and if found then copy it in another file? Using sed -i we can find text but how to copy whole line in another file?
0
votes
0answers
10 views

Postgres server start fails - netstat -ant|grep 5432 output explanation?

I'm working on a Ruby on Rails app. Hosting on Heroku with postgres. Tried running "heroku run rake db:migrate" as usual, but getting error "cannot connect,... check if something else is already ...
2
votes
3answers
38 views

grep .* returns results from .bash_history and complains about

I'm new to Linux and so far I've been playing around with some utilities, specifically the grep utility. I decided to create a new file (aptly called 'newfile') with the following content: Lady of ...
4
votes
3answers
27 views

Timing of ps piped to grep

So, this isn't a problem as such, just something I'm curious about. I'm using Linux Mint MATE which is branched off Debian. If I do: ps afx | grep abcdefg I get: 16599 pts/3 S+ 0:00 | ...
1
vote
2answers
42 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
23 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
72 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
356 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
45 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
34 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
264 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
30 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
163 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
85 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
443 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
54 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
45 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
48 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 ...
0
votes
2answers
47 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
203 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
16 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
24 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
100 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: ...
2
votes
6answers
159 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
30 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
141 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
47 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
75 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
39 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
86 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
40 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
170 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
49 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
44 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 ...