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

learn more… | top users | synonyms

1
vote
3answers
35 views

How to pick out files in a folder in which the header contains specific text?

Use case: Let's say there is a folder full of large RDF+XML files and they follow different namespaces. We want to find those files that follow a given namespace (for example ...
1
vote
5answers
45 views

grep words around a token

I have some lines in a file like: This is one word1:word2 of the lines This is another word3:word4 of the lines Line without a match Yet another line word5:word6 for test I need to grep ...
0
votes
2answers
44 views

Read file and find all occurances and generate hash for the content in between the occurance

I have a file like this : 1 Record|1111|ABC 2 text in between for record 1 3 text in between for record 1 4 Record|2222|XYZ 5 text in between for record 2 6 Record|3333|XYZ 7 text ...
0
votes
1answer
47 views

No output from grep -P 'com\K\w+'

I have a source file saved off the internet which has various links I want to pull data from. For example https://blahblah.com/uniquetext I'm using grep -oP 'com\K\w+' source.txt > list.txt ...
1
vote
2answers
102 views

grep pattern exacly matching from file and search only in first column

I have a bigfile like this: denovo1 xxx yyyy oggugu ddddd denovo11 ggg hhhh bbbb gggg denovo22 hhhh yyyy kkkk iiii denovo2 yyyyy rrrr fffff jjjj denovo33 hhh yyy eeeee fffff then my pattern file ...
1
vote
2answers
128 views

How to grep for something that's in an environment variable and has a forward slash?

I want to grep a file, and I want to get all the lines that have a certain environment variable (to be exact, $PWD). Of course, using just cat file | grep '/'$PWD'/' is not working, since $PWD ...
5
votes
2answers
127 views

Suppress 'file truncated' messages when using tail

I'm tailing a log file using tail -f messages.log and this is part of the output: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce eget tellus sit amet odio porttitor rhoncus. Donec ...
2
votes
1answer
56 views

How do I grep for multiple patterns on multiple lines?

To be precise Some text begin Some text goes here. end Some more text and I want to extract entire block that starts from "begin" till "end" with awk we can do like awk '/begin/,/end/' text ...
2
votes
7answers
224 views

Formatting the output of grep when matching on multiple files

When searching on multiple files, the output of grep looks something like this: {FILE}:{MATCH} This is a problem since if I double-click on the {FILE} portion, I will at least also select (and ...
1
vote
0answers
24 views

Review GREP and FIND results in Xemacs

I spend a lot of time searching code. I really like grep and find, because of all the options available. But it takes way too long to navigate the results. I use xemacs and it takes 3 more commands ...
1
vote
2answers
20 views

Zero input_file_names in Grep

From the manual for grep, the general form of grep usage is: grep options pattern input_file_names In particular, it is stated "There can be zero or more input file names." What files are ...
0
votes
1answer
25 views

How do I add text to an output file?

I have a script for doing whois lookups: #!/bin/bash for domain in `cat /Users/jason/Desktop/letters.txt `; do echo $domain >> /Users/jason/Desktop/whois-results.txt whois $domain | grep ...
0
votes
2answers
27 views

Grep matching cell of the csv file and index of that row

I have csv file and I want to see numbers that start with 0.99 and their row's index which is the first cell of that row. This is what I have so far: cat fil.csv | grep '0\\.99'| tee > (cut -d, ...
3
votes
3answers
126 views

Grep for searching pattern in a file

I want to use grep to search pattern from one file in a second one. My pattern file is something like: K02217 K07448 KO8980 The file to search in is: >aai:AARI_24510 proP; proline/betaine ...
6
votes
1answer
135 views

Conditional grep without quiet option

I always thought the quiet (-q) option had to be used when using grep conditionally. But re-reading the man page it seems like it should work without it. So if you want to print matches and use it in ...
0
votes
2answers
68 views

Unix grep confusion

I am doing an assignment for school and using putty to complete the assignment. The format of the assignment does not allow for much variation and thus only one answer is sufficient enough to allow me ...
2
votes
1answer
41 views

Help with using quotes in grep searches

I have a file with variables in it of the form a(i)%b(j)%c where the a, b, and c are always the same, but the indices i and j may be different (including multiple characters). So I've played around ...
1
vote
2answers
56 views

Seaching a File in Unix for a given string and then another set of Strings within this file and print file properties too

I am using command to search for files staring from a given Directory in Unix , files ending *.sas and containing the string DB2. I then inturn want to search the resultant set of files for the ...
1
vote
2answers
175 views

Is grep part of coreutils? (If not, why?)

I have read in a few websites that grep comes with coreutils (e.g. https://wiki.archlinux.org/index.php/Core_Utilities) However, after building them, I noticed that grep is missing. I wonder if I ...
1
vote
3answers
90 views

Print total free memory from `free -m`

free -m currently puts out something like this. I would like to know using grep/awk how we can get the total free amount. i.e. 9083
0
votes
3answers
81 views

Simple way to extract value from HTML

I have a very simple html file with a value inside. Value is 57 in this case. <eta version="1.0"><value uri="/user/var/48/10391/0/0/12528" strValue="57" unit="%" decPlaces="0" ...
0
votes
1answer
388 views

How to execute grep in tcl for getting XYZ-123 type pattern

How can I execute this grep command in TCL? grep '[A-Z][A-Z][A-Z]\-[0-9][0-9][0-9]' file1 > file2
2
votes
1answer
22 views

egrep multiple patterns with dashes

I am trying to match the followings with egrep '201411[08|09|10|11]-[117|111]-' 20141108-111-xyz-abc 20141110-117-342-lala But for some reasons, the 2nd character class pattern ([117|111]) doesn't ...
1
vote
2answers
88 views

Search 2nd line of files and print filenames to stdout

I have a few directories of ~10,000 files. What's the quickest way to search each file and return the filename if the second line contains a specific string? Edited for clarity
1
vote
2answers
44 views

find field pattern in a csv file then count unique field values

I am using Cygwin (bash) to create a script to find, group and count fields in multiple CSV files. Each row will have comma-separated fields with each field following a similar convention. There is a ...
3
votes
3answers
202 views

How can I delete all text between curly brackets in a multiline text file?

Example: This is { the multiline text file } that wants { to be changed } anyway. Should become: This is that wants anyway. I have found some similar threads in the forum, but they don't seem ...
-1
votes
1answer
44 views

Information about grep cammand [closed]

Both two outputs came in my terminal. sda 13.45 479.55 84.92 812139 143808 sda 5.00 4.90 4.00 13 24 I want to get ...
1
vote
5answers
64 views

Regular Expression for Mixed cased words

I want a regular expression that will help me identify if a certain pattern is present as a mixed case in a sentence or not. Say: Fox juMPed the rock Now, I want to find that if the pattern ...
2
votes
6answers
88 views

Getting the matched word exactly

I have looked through a number of question but they do not satisfactorily reply to my question. I need to print words that match the pattern exactly not the lines containing that word. For example: ...
3
votes
1answer
61 views

How to format grep results?

Wow, I could not think of a good way to title this question. Basically I have a file called "attendance" with data like this: 11/06/2014 101.11.001.01 FirstName LastName 11/06/2014 101.11.001.01 ...
2
votes
1answer
67 views

grep of a shell variable finds nothing

I have some problem with grep. I wrote a script which need to find some numbers from a list (file name ContigsNames) in a database. I wrote the following script: file=ContigsNames while IFS=' ' read ...
4
votes
0answers
94 views

what is grep -v -f /dev/null expected to do exactly?

Theory: grep -f somefile or grep --file=somefile will find all lines that match one of the patterns listed in somefile. If somefile is empty, nothing will match. With grep -v you list lines that do ...
2
votes
3answers
48 views

Removing lines from one file based on non-existence in another

I need to remove lines from fileA which has two columns if fileB (one column only) does not contain the string from column1 in fileA. Any linux command would help. Thanks. Example. Here is fileA: a ...
7
votes
3answers
152 views

Is there a way to make this one-liner faster?

Context I have a directory of thousands of zip files that are dated in the form YYYYMMDD_hhmmss.zip and each about 300K. Within each zip file is about 400 xml files each about 3K. The problem I ...
0
votes
1answer
13 views

add fields from different lines in one line

I'm trying to add the .data and .bss sections of the size -A output size -A mylib.so | grep "\.data" | awk '{print $2} this will print the value of the size of the .data section. I guess I could ...
3
votes
3answers
67 views

How can I base the file name off of an already existing variable?

I'm using this to delete lines that don't match a pattern: $ egrep "pattern1|pattern2|pattern3|pattern4|pattern5" But now I need to do it automatically, so I'm setting a variable like this: $ ...
0
votes
3answers
76 views

How do I search a file for a string then use it as a variable?

I have an XML file that looks like this: <id>456</id> <root> <value>1</value> <intNum>2</intNum> </root> <root> <eulav>1</eulav> ...
0
votes
2answers
32 views

Delete consecutive lines if patterns match in each line

Good day, I was wondering how to delete to consecutive lines when this pattern is found: /^pt [a-z]\npy [0-9][0-9][0-9][0-9]\n// Expected Input pt a py 01234 pt b cd abc py 5678 Expected Output ...
2
votes
1answer
50 views

how to use grep -v in an expect script

I'm new to expect scripting, trying to implement below command (that works otherwise) in an expect script $ grep -i cps config.cfg | grep -v "//cps" | grep -v "cps := 4.1" | \ grep -v "cps := ...
0
votes
1answer
63 views

Grep -m 1 doesn't work

I'm using the following command to parse a form element from HTML using grep. The $RESP variable contains the output from a previous curl request ... echo $RESP | grep -m 1 -o -E 'name="id" ...
0
votes
0answers
40 views

How to prevent grep from excessive unnecessary memory usage

I'm greping a hexadecimal pattern (currently a number) from a large binary file (1 TB) with xxd -p /path/to/sda.img | tr -d '\n' | grep -ob '117a0cb17ada1002' and I'm wondering why grep uses up to ...
2
votes
4answers
63 views

How do i Reverse output already piped from sort and cut commands

I have to take user input of there UID then use it to reference the /etc/passwd directory and sort the data by first name and display only username,firstname,lastname in that order. The problem i'm ...
1
vote
1answer
45 views

Linux log file structure change for usage with kst

My file (tcp dump from networked sensors) has this shape: 20:06:57.049686 IP (tos 0x0, ttl 64, id 26871, offset 0, flags [DF], proto UDP (17), length 68) e108-193.eduroam.tugraz.ac.at.34225 > ...
1
vote
3answers
68 views

How to sort the filenames shown in grep command based on timestamp?

In the following command, how can I get the file names based on its timestamp $ grep "exit 0" a* a1.txt:+ exit 0 a2.txt:+ exit 0 a3.txt:+ exit 0 a4.txt:+ exit 0 a5.txt:+ exit 0 $ ls -latr ...
2
votes
1answer
41 views

Extend grep to find a match after the first match

I have a long list of strings separated by newlines and each section separated by a string starting with ~ (there are no other ~ in the file). I want to extend grep to find the ~ text right below the ...
1
vote
4answers
37 views

How to do grep even if the file is not present?

I am doing something like this in my code file_nm=`ls -latr *abc*` if [ `grep "search_txt" "$file_nm" | wc -l` -gt 0 ] then echo "string found" else echo "string not found" fi If the file_nm is ...
1
vote
2answers
91 views

double grep on tail -f gives no output

If I follow a file somehow like this: tail -f /var/log/syslog|grep s I see all lines containing an "s" Why does this not give any output, if I grep it again to the same "s"? tail -f ...
1
vote
1answer
68 views

How to grep the logs for a list of patterns and make a report out of it?

I have a C++ executable which scan some of my files and those files has some user id in it. After scanning is completed it generates below log file (abc.log) like this - INFO [0x7faff2b32a00] ...
4
votes
4answers
170 views

How to remove all comments from a file?

I have a file with a few lines commented out: foo bar stuff #Do not show this... morestuff evenmorestuff#Or this I just want to print all the uncommented code: foo bar stuff morestuff ...
-1
votes
3answers
63 views

Find files less than 1 week old with match TODO in files

My unsuccessful proposal find ./ -newerct '1 week ago' -print | grep TODO No output although should be. Files are text files like Lorem % TODO check this out Lorem ipsun How can you find less ...