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

learn more… | top users | synonyms

0
votes
3answers
32 views

Throw away standard output and error

I have redircted my ouput using /dev/null in bash script but it is still throwing an error. Code is following ps -p $proc | fgrep $proc> /dev/null if [ $? -ne '0' ] ; then ...... fi below is ...
-3
votes
2answers
33 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
122 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
38 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
37 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 ...
-1
votes
0answers
34 views

How to merge these three task in a single command ( grep | sed | echo)

I am trying something where I parse out from the tags in a file then add back the HTML. I see everyone suggest not to do such with regEx (grep). but here it is grep -m 1 -oP ...
2
votes
1answer
56 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
119 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
28 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.
3
votes
3answers
240 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
votes
0answers
29 views

Skip Duplicate Output [duplicate]

I using this command to print an output :- grep -a --binary-file=text "RRRR" /home/path/file.log-$1* | awk -F, "/$line/ {print \$2 \",\" \$9 \",\" \$10 \",\" \$11 \",\" \"(\" \$23 \")\"}" example ...
1
vote
2answers
32 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
87 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
53 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
38 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
60 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
77 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
24 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
43 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
49 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
62 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
35 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 ...
1
vote
4answers
216 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
44 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
88 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
48 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 ...
7
votes
3answers
141 views

How to use [\w]+ in regular expression in sed?

I am on Windows, but I guess my question is still rightly placed here. C:\Users\User>grep --version GNU grep 2.6.3 C:\Users\User>sed --version GNU sed version 4.2.1 I noticed that the ...
1
vote
2answers
32 views

Using Unix, when detecting a pattern, we need to detect its corresponding other pattern

When detecting the line containing the pattern night, we need to detect its corresponding line containing the other pattern === which is just occurring at a higher line as shown below. File content: ...
6
votes
2answers
681 views

bash - why does \x0d\x20 erase the line

This is the view from gedit editor: and the view from vim editor: I then try to grep it, it did grep successfully if i put Log instead of Tog, but the output is corrupted: [xiaobai@xiaobai grep]$ ...
3
votes
4answers
46 views

Find the last occurence of a string in a given filetype in all subdirectories

I have multiple sub-directories each with different depths. I need to search for the last occurrence of a string in a specific filetype (say *.out). How can I accomplish this? I have tried: grep -r ...
0
votes
3answers
31 views

To grep version number from Wordpress plugin folder

What will be grep regex to extract version number like Version: 3.1.5 * Version: 3.1.5 Will output 3.1.5 But It should not catch likes MIME-Version: 1.0\n Here is my grep command grep ...
1
vote
0answers
16 views

tool in terminal like helm-occur/helm-swoop for terminal?

I don't know whether this is the right place to post this question, but if you are not an Emacs user, I'll explain the basic usage of helm-occur/helm-swoop. I like helm-occur/helm-swoop for Emacs ...
1
vote
2answers
57 views

Pipe to my own script

I've recently noticed this message from grep "grep: warning: GREP_OPTIONS is deprecated; please use an alias or script" I receive this warning because --color=always is defined in my .bashrc file. ...
0
votes
4answers
69 views

What the equivalent of “grep | cut” using sed or awk?

Say I had a config file /etc/emails.conf email1 = user@dinkum.dorg email2 = user@winkum.worg email3 = user@stinkum.storg and I wanted to get email2 I could do a: grep email2 /etc/emails.conf | ...
0
votes
1answer
24 views

Filtering Log Output on Separate Lines

I did a recursive grep in a directory to find all files that would match as follows grep -ER "match_string1|match_string2" /path/to/dir/ What I get as output is: ...
0
votes
2answers
30 views

grep to ignore special characters in a file [closed]

I have a java file and I want to list the number of times the word port occurs. But the only problem is I have many functions which have the work port in it too. Here is an example of a function : ...
1
vote
1answer
33 views

How to filter a basic csv by columns

How do I filter by third column of the following file list.txt [[ list of people ]] billy baxter - @baxter - b.baxter@woods.com james woods - @woods - j.woods@someother.com I currently have cat ...
1
vote
2answers
49 views

awk/grep to match word in two files [duplicate]

I have two files: file1: 905894 1197693 3703749 file2: 905894 Test1 1197693 Test2 3703749 Test3 I want to get the values in the second column if elements in file 1 column 1 matches any of ...
0
votes
2answers
45 views

find and list -R returning different number of files

I'm trying to create an array variable with a list of files to use in a small script, needing the full path to the file. Looking around I tried something like this: find /path/ -t f | grep ...
6
votes
3answers
155 views

Get files with a name containing a date value less than or equal to a given input date

One of my folders contains files in the following format: 3_20150412104422154033.txt 3_2015041211022775012.txt 3_20150412160410171639.txt 3_20150412160815638933.txt 3_20150413161046573097.txt ...
0
votes
1answer
41 views

Script for update

I need your help in a script used for update : OLD="int 10" NEW="int 20" i=0 DPATH="/home" for f in $DPATH do sed -i "s/$OLD/$NEW/g" $f let i++ echo "modified:" $f done what i need ...
2
votes
1answer
48 views

Execute commands from history that match regex or grep

I was wondering if its possible to execute commands from history that match a certain regex? I know you can do something like fc 232 248 And it will go into your history and then do revisions ...
1
vote
1answer
60 views

Awk Command vs Grep

I had a question regarding the awk command. I want to take a bunch of files and find a single line from each and extract them into a comma seperated text file such that I can import it into excel for ...
2
votes
2answers
166 views

Extract group name from `id` and store it in a variable

$ id usera uid=830(usera) gid=799(groupa) groups=799(groupa) I need to extract the group name from the output of id and store it in a variable. In this case it's groupname=groupa
0
votes
4answers
84 views

delete all .swp file using rm command

I am trying to find and delete all .swp files in my current directory. I was using below command: rm -i `find . | grep .swp$` But everytime it is giving me this error: rm: missing operand Try `rm ...
3
votes
1answer
122 views

Want to grep a date in a file and its next 5 lines

I want to grep the current date in a file, but also output the next 5 lines. How do i do that with the grep or anything else. grep -A 5 file.txt does not work and the output is shown below. Please ...
1
vote
2answers
46 views

How do I get a count of file references inside a folder of files with those references?

Alright, I have two folders. For simplicity's sake, I'll call them people and animals. The animals folder has a file for each animal, and the people folder has a file for each person with references ...
0
votes
1answer
45 views

Search and replacing strings in a numerical data file

I have a data file I need to edit it is in the form: ...
4
votes
1answer
83 views

How to tell “grep -w” what characters make up “words”?

$ printf 'asf .test. afd\nasaf foo-test asfdads\n' asf .test. afd asaf foo-test asfdads $ printf 'asf .test. afd\nasaf foo-test asfdads\n' | grep -w test asf .test. afd asaf foo-test asfdads ...