Tagged Questions

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

learn more… | top users | synonyms

0
votes
4answers
137 views

grep to see if a line ends with a particular string

Hello I have a file that has a lot of lines that end with main.css">, and some of them are repeated. I want to keep only one copy of these lines and delete the repeated line. Could I use grep to ...
1
vote
2answers
378 views

Aix grep wildcard not working

I have a file called message that has the line CSC/UT/USA/WBIMB/SAP/orders05:orders05/ORDERS05/NONE/ORDRSP/758 I am doing a grep (Platform is AIX 6.1) grep ...
0
votes
2answers
126 views

How can I grep for broken HTML tags?

I want to grep through all my HTML files and see if I have any bad tags there, example <br> , <hr> and so on, that is the I want to see what tags are not closed in the HTML file. for ...
0
votes
3answers
61 views

How do I match a string with symbols in a grep-kind of way? [duplicate]

I have a file with this contents (or similar): # cat /var/www/htpasswd foo:$apr1$73wJ8tiQ$HdaRYe2pUMqBf0ZpMJz6h/ and I'm trying to verify the presence of an entry in it, by matching it, like this: ...
2
votes
5answers
209 views

how can I print the Nth and the Mth line above or below the matching line with grep?

Let's say I have a well-structured text file with following content(no leading line numbers): 1 Mon Jun 9 00:11:47 CST 2014 2 eth0 Link encap:Ethernet HWaddr D4:BE:D9:F5:5C:0E 3 ...
2
votes
3answers
965 views

GREP / SED or AWK: Print entire paragraph in a file on pattern match

I have a file with hundreds of paragraphs of around 15 lines each. I need to search for a pattern, say Occurance: 1. If this pattern is found in the para, I need to print the entire paragraph. Note ...
4
votes
3answers
114 views

How do I combine the -v and -B switches in grep?

I have a list of currently installed kernels, and I'm trying to grep out both the currently installed kernel and the previously installed kernel. For this example, linux-image-3.2.0-60-generic is the ...
0
votes
1answer
61 views

How to output the lines of a file after find and a grep?

Hello I want to output ERROR messages from logfiles from the current date. First I search for the logs of today with specific prefix: find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" ...
0
votes
2answers
42 views

How can I search filenames which are starting with xy_* and are created/edited today?

Hello I´m currently trying to search for logfiles which are starting with xy_Number and are created/edited today(not last 24 hrs). I tried: find /home/USER/logfilesError/ -maxdepth 1 -type f ...
10
votes
2answers
494 views

Filter output of command by color

I am running a utility that doesn't offer a way to filter its output. Nothing in the text of the output indicates that a particular function failed but it does show in red. The output is so long that ...
1
vote
3answers
462 views

GREP for Processes by Directory and Kill it

I'm trying to grep for processes that originate from the /Applications/ directory (to kill them), but my grep command keeps catching some false ones as well. What am I doing wrong here? $ ps -ef | ...
2
votes
3answers
214 views

Find a pattern with no repeated numbers in egrep

I need help finding a regular expression to match all digit sequences which has no repeated digit. Example: 198345 -> matched. 198315 -> not matched (1 repeated twice ) How can I achieve this in ...
6
votes
6answers
465 views

Check if a variable contains only what I want, and nothing else

I'm writing a script to build a software from sources, and there's a --platforms option. I would like to allow the user to select multiple items, but I don't know how to prevent them from making a ...
1
vote
2answers
83 views

grep a keyword from Mplayer output and send the rest to file

I am using mplayer. I want to send everything to a log file (/tmp/server.log), but I want the Volume output to be written to the terminal. I have seen that there is a way to split the output with tee, ...
3
votes
3answers
245 views

How can I get the first column of a 300GB txt file?

let me first explain my problem in detail. It's actually pretty simple. I have a huge .txt file, 300GB to be more preciese, and I would like to put all the distinct strings from the first column, that ...
0
votes
1answer
377 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
1
vote
4answers
93 views

Getting data under or above a line

This is my file: print energy 1 end Local net energy (PE 0) = 1.635393034217E+05 kJ/mol Global net ELEC energy = 1.635393034217E+05 kJ/mol print energy 2 end Local net energy (PE 0) = ...
1
vote
1answer
86 views

Using `tac` on zipped files

tac unzipped.log | grep -m1 pattern works perfectly fine but I am not able to use the tac command on zipped files. tac zipped.gz | zgrep -m1 pattern returns nothing. Is there anyway to use tac ...
2
votes
3answers
173 views

grep on a Java Method

Lets say I have a java class called DirectAction some of the methods in the class have the word "action" or "Action" What is the grep command to get the names of all the methods who have "Action" or ...
7
votes
3answers
3k views

What are the exact differences between awk and cut with grep? [closed]

We know that we can get the second column of the line we want from a file using these two techniques: awk '/WORD/ { print $2 }' filename or grep WORD filename| cut -f 2 -d ' ' My questions are: ...
6
votes
10answers
2k views

Copy only Specific text of a file to another

I have a file abc.txt the contents are <classpathentry kind="src" path="Sources"/> <classpathentry kind="con" path="WOFramework/ERExtensions"/> <classpathentry kind="con" ...
1
vote
3answers
150 views

Returning only the portion of a line after a matching pattern (Unix)

I have a parent folder (abeps) which contains several sub folders (1,2,3....25) where output file is located, one in which - all are the same name (opt.out). In this files there is an unpredictable ...
2
votes
3answers
216 views

conditional coloring in grep

I have a simple bash script. One line of my script matches a "pattern" with grep and colors the match grep -i --color=always -- "$1" I need to modify it, so that it only colors the match, if the ...
0
votes
4answers
381 views

Search for a Value only in one column w.o using awk, sed, or perl

I have a file that looks like this : Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles Karen Thompson Sales Peter RobertsonPARTGolden ...
1
vote
2answers
275 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
4
votes
1answer
168 views

Blank lines when executing “grep | xargs” in a “find -exec”

I'm trying to list all directories of a web server that are blocked by Apache via a .htaccess (containing deny from all). I've managed to get the list of blocking .htaccess but when I try to extract ...
5
votes
3answers
3k views

Recursive grep vs find / -type f -exec grep {} \; Which is more efficient/faster?

Which is more efficient for finding which files in an entire filesystem contain a string: recursive grep or find with grep in an exec statement? I assume find would be more efficient because you can ...
0
votes
1answer
109 views

Duplicate specific text in text file, using perl or grep

I need to duplicate part of a plain text file as follows: The text file consists of a sequence of "pages", of the form: <page [lots of lines of text] /page> <page [lots of ...
3
votes
2answers
87 views

how to grep complex hierarcy?

I have a file as:- start apple 1 a 2 b 3 c start orange 4 a 5 b start mango 1 a start a/b/c 5 z end 4 b end 6 c end start banana 3 c end 4 d 5 e end I want the output as :- 1 apple/a 2 apple/b 3 ...
2
votes
1answer
80 views

Globbing fails in zsh, but works in bash

I have an alias in bash, that I'm trying to port over to zsh. I thought it may have been the alias itself, but now it seems it's just the globbing. grep -irl --exclude=\*.{log,class,fuegoclass,dat}* ...
3
votes
5answers
128 views

How to “grep” a string of a returned result

How to grep the number 50.0 from the string temp=50.0'C In JavaScript I can use the expression /temp=(.*?)'C/ to get it. But I cant get it running in grep.
2
votes
1answer
126 views

How to find text in files and only keep the respective matching lines using the terminal on OS X?

I am pretty new to the terminal and command lines, from what I have found out grep seems to be the right tool for search files for specific text strings. I have a folder with many huge text files and ...
1
vote
7answers
2k views

Can grep be used for searching files with some string in their names?

I understand that grep can only be used for searching for files which contain a string in their content. Can it be used for searching for files with a string in their names? I read the manpage, and ...
3
votes
2answers
404 views

Grep log and get text between log delimiters

Is there a way to grep a log and find text between the log entry delimeters? Our log file separates the line entry with characters "-------" So when I search the text word I want all the lines before ...
6
votes
4answers
2k views

Why doesn't grep using pipe work here?

I have the following command: find / -name libGL.so.1 Which returns lots of lines with "Permission denied". I want to exclude such lines, so I added the following: find / -name libGL.so.1 | grep ...
0
votes
1answer
114 views

Grep : Find all possible cases of a word in text file

I have a directory with many text files. Out of these files, I am interested in a word "abcdefghi". I need to list all possible cases of this word such as abcdefghi abcdefghI abcDefghi ABCDEFGHI ...
2
votes
3answers
95 views

Make grep work for special filenames

I have a set of txt files whose names may contain space or special characters like #. I have a grep solution grep -L "cannot have" $(grep -l "must have" *.txt) to list all the files who have must ...
1
vote
3answers
1k views

Find files containing one string but not the other

I am in a folder with lots of .txt file, I would like to find all the files which contain stringA, but don't contain stringB (they are not necessarily in the same line). Does anyone know how to do ...
1
vote
0answers
33 views

Filter partial output of some script [duplicate]

I need to analyze the output of some script So, I know their header and their tail of some part of the output script, but not the content. I found an approach [1] But I need something like: $ ...
4
votes
1answer
100 views

Redirect grep out to a file does not work [closed]

I am doing a recursive grep by the following command: grep -r "load" . > tmp.txt However, when I hit enter, the command does not execute and bash is waiting for more inputs.. My OS is Ubuntu ...
1
vote
1answer
140 views

grep file from file

What is the fastest way to grep -v a file against another one, both line by line. does grep support this ? Or should I use it on two for loops ?
3
votes
1answer
154 views

pcregrep newline lookbehind assertion bug?

Attempting to use pcregrep to print the first line after a blank line. For example, contents of file first line second line I need second line to be printed. Here are a few tests using the same ...
-1
votes
3answers
147 views

How can I run a grep on epub/mobi files?

Is there a way to do it, particularly on a set of multiple epub/mobi files in one directory?
-1
votes
4answers
382 views

How to exclude directories from `ls -R` output?

If ls -aR | grep ":$" returns ./.hiddendir2: ./dir1: ./dir3: ./dir3/.hiddendir4: then how can you update the pattern given to grep so that you only get ./dir1: ./dir3: (note that the last ...
2
votes
2answers
462 views

grep print relative file path when doing a recursive search

I'm trying to find out which version of hibernate the project depends on (this is orthogonal to my question). We have a parent project with several sub projects, and I know this is defined in one or ...
2
votes
4answers
192 views

Color matching but print other lines too [duplicate]

I have an alias: alias grep='grep --color=auto'. I wish to have some way to print not only matching row but all of them and just color matching patterns. I doubt is there an option to do that in the ...
0
votes
1answer
120 views

How many times does the same character occur twice in a row

My task is using grep to find how many times the same character occurs twice in a row. I was thinking about something like this but it isn`t working grep '[a-zA-z]{2}' *.txt | wc How can achieve ...
1
vote
2answers
73 views

Parse,Manipulate Data In linux/Unix

I want to have exactly the same output in this post(http://unix.stackexchange.com/questions/126139/extract-data-in-linux-unix)as above,but I have a new input file,which is below: ABCB11 4 ACE 11 ...
0
votes
2answers
2k views

How can I use grep to search multiple unnested directories?

It may sound like I'm asking the same thing as this question, but I have different requirements. This is an example of my filesystem: /code/ internal/ dev/ main/ public/ dev/ main/ release/ ...
5
votes
2answers
121 views

Why does a grep reboot the machine?

On a RHEL 6.5 Desktop, if I use: sudo grep -r foo /* my desktop reboots. Q: Why?? How to debug this? It's the third time my Desktop reboots because of this :D