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

learn more… | top users | synonyms

0
votes
0answers
23 views

print duplicate fields in different columns from two files using awk

I have two large files. I am attempting to identify and print any duplicate fields to a new file. I have a 19 columns and over 100k rows. I need to compare columns 5-19 for duplicate values. ...
0
votes
3answers
50 views

parsing out duplicate barcodes in a separate line

I've got the following data I need to parse out the duplicates from column1 into a separate file, For example, 21288003132541:cr 21288003267289:fr 21288003758683:ph 21288003758683:tag ...
-2
votes
1answer
27 views

exclude names without a comma

How do I exclude names from my list that have no comma and output them to a file? Should I use grep? Example: Charlie Chapman William, Henry Gary, Stevens Mark Twain Harry Potter Smithy, John Mon
1
vote
4answers
76 views

“head” only printing one line?

I've got a CSV file that's generated by saving as CSV from Excel. If I do "head" (or indeed "grep" or anything else) it only prints the first line: head -n 10 messy.csv 10,15,11,21 But if I open ...
2
votes
3answers
40 views

Split command and arguments, and put into variable in a bash script

I have a script that repeats the same (very long) grep command many times. I want to make the script more readable by cutting the line length, so I tried to put parts of the command into variables. ...
2
votes
4answers
67 views

Print alternating lines with conditional

Still struggling with messy logfiles. What I want is to find lines that first matching string X and then string Y. I then want to print them together. The problem is that, sometimes there is X, but no ...
1
vote
1answer
16 views

Filter screenlog with screen command

Pressing Ctrl+A, H, lets me log output of the screen command. However, the output file is too large. Is it possible to apply a grep-like filter so that I can control what gets logged? For example, I ...
7
votes
4answers
296 views

How to grep-inverse-match and exclude “before” and “after” 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: all_lines except ...
4
votes
1answer
51 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
56 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
99 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
531 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
59 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
40 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
44 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
47 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
11 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
28 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
24 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
74 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
358 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
37 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
271 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
168 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
86 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
467 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
48 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
206 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
18 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
103 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
161 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
32 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
151 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
48 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
76 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 ...