grep is a command-line utility that is used for searching text.

learn more… | top users | synonyms

3
votes
2answers
39 views

grep regex pattern causes unexpected command behavior

I'm searching for lines with $ and consecutively ' or " through this grep in my terminal: grep "\\$('|\")" -rin folder_path After pressing enter the terminal doesn't think the line is complete so ...
-1
votes
1answer
28 views

How to compare/fetch the greater value in perl script? [closed]

Trying a perl script to fetch the % of hard disk usage. [By fetching the 5th column of the 'df -H' output, shows percentage of use]. $thirdlast=`df -H`; @matches=($thirdlast=~/(\S+%)/g); print ...
1
vote
1answer
38 views

I cannot get grep to print results

Total noob here. I am blindly stumbling my way through bash. I realize that there is a syntax error in the following script but, I cannot figure it out. The script just sits there. #!/bin/bash ...
3
votes
1answer
20 views

Store in environment variable

I tried storing the contents of a file in an environment variable using one of those commands. a= cut -f 1 abc.txt cut -f 1 abc.txt >a neither works . So , can anybody help me out?
3
votes
2answers
45 views

Automatically doubling the value of numbers in a string in multiple files

I'm trying to modify Java source code in numerous .java files that contain strings similar to this: private static final Height biomeHeight = new Height(0.1F, 0.2F); There are over 75 and I'd like ...
0
votes
3answers
36 views

Given some number, use grep to find where the number belongs in a numbered list?

I've got a number (lets say 13) and I want to find where it would belong in an incomplete numbered list. Here is an example list: 1 3 4 5 9 16 17 21 Obviously the 13 would go between the 9 and the ...
8
votes
2answers
318 views

How to use grep output as a path for cd?

How can I pipe grep output as an argument to the cd command? For example: [root@xxx xxx]# pip install django | grep '/usr.*' Requirement already satisfied (use --upgrade to upgrade): django in ...
1
vote
3answers
44 views

What does this egrep command do?

I run this command egrep "\" string_demo | wc -l I got output below: akshay@akshay-K53SC:~/shell$ egrep "\" string_demo | wc -l > abc > pqr > xyz > ">" will continue until I press ...
0
votes
1answer
33 views

Grep/egrep not working correctly?

I seem to be using grep incorrectly. Observe: > hg log <filepath> | egrep changeset changeset: 3961:9dedc55e030a changeset: 3651:d23495ab1168 changeset: 2974:6aa71cb2c575 changeset: ...
3
votes
1answer
51 views

How to run a single command multiple times while changing one word in the command each time it is run?

I've got a command like this: grep word1 file.txt | grep word2 | grep word3 I want to be able to run this entire command multiple times while changing the value of "word1" each time. I have a file ...
1
vote
1answer
47 views

How to filter out links from html using grep or sed?

I am trying to filter the links related to the src attribute from the html of a web page. I used curl to get the html and below sed command to filter the url links. curl -s http://www.example.com/ ...
2
votes
1answer
117 views

copy several lines from one file to another

I would like to use grep in order to copy from one file to another all lines that are between lines /protein_id= untill the end of the protein sequence shown. For example, from this input: CDS ...
3
votes
3answers
69 views

Move pattern to beginning of line

I am trying to reformat a log file such that date and time appear at the beginning of the line. My logs look like this: blah, blah, blah, Friday, Mar 13,2015 16:59:42 yadi, yadi, yada, Friday, Mar ...
2
votes
2answers
237 views

Need a hand with a grep word command

Just getting the hang of Linux Command Line, but having trouble with grep commands. I'm trying to find out how many times a word appears in the last 1000 lines of a text file I have a feeling that ...
0
votes
1answer
41 views

How to I parse a file and only keep certain words?

Let's say I have a list of words I want to keep. list=['hi','name','first'] I want to be able to go through a text file, keep each and every word in my list, and output the new cleaned up content ...
3
votes
1answer
252 views

Use a list of words to grep in an other list

I've got a list with 250 lines in it. I have to run all of them through a web server to get a list of output. This list, however returns many more lines, than I'm interested in. Say, my list.txt is: ...
3
votes
5answers
319 views

Extract part of a line upto a particular string

Let us assume I have a file with lines like: /java/jdkxx/jvm_jdk/bin/opt /java/jre/jre_jvm/bin/opt /foo/bar/bin/other/stuff/here Is there a way I can extract part of the lines upto bin. I mean, ...
0
votes
2answers
30 views

Grep : Filtering Question

I need to construct a regular expression that will filter a group of words that begins and ends with the same word. For example, the life of the free will output the life of the and he was and he his ...
5
votes
4answers
882 views

Grep searching two words in a line

I've been trying to find a way to filter a line that has the word "lemon" and "rice" in it using a regular expression. I know how to find lemon or rice but not the two of them. They don't need to be ...
0
votes
1answer
35 views

grep single pattern having more than one matches

I have a file (X.txt) with a list of unique entries. I would like to use this file to grep from another File Y.txt which contain more than one entries for single pattern of X.txt. X.txt contains: ...
-1
votes
3answers
103 views

grep — list file name where match is found

I have a bunch of .html files in a directory. I want to look through each file and match a pattern (MD5). All of that is easy enough. The problem is I need to know what file the match was found in. ...
1
vote
2answers
131 views

Grep strings in a subgroup of lines in txt file

I have a file that looks like this AAA_21 PF13304.1 x_00004 AAA_22 PF13401.1 x_00004 SMC_N PF02463.14 x_00004 AAA_29 PF13555.1 x_00004 ...
-2
votes
1answer
346 views

How to combine ls and grep to list only files and using ls to count dirs

I have some troubles with combining ls and grep. The thing is that I have to use only ls and grep to list all files in home directory. Ive tried multiple of combinatnions but with no effect. I think i ...
0
votes
0answers
15 views

Where is php.ini when I install APC?

I am trying to install APC on Ubuntu 12.04, I faced some problems. I used this link: http://www.inmotionhosting.com/support/website/php-configuration/install-apc-for-php I then solved all the ...
0
votes
1answer
50 views

Match Pattern and write following value as variable

I'm trying to match a pattern and then pull the following information to create a file using that variable. Example (my data may look like either of the 2 examples) "headers": { ...
2
votes
1answer
146 views

grep - highlight inside a highlight

I'm facing difficulties while trying to multicolor-highlight matches using grep's color environment. After I stumbled across Colored grep, I found it very useful to highlight multiple pattern in a ...
1
vote
1answer
55 views

put multiple matches on one line to a new line using grep

I need to put multiple matches on a line each on a new line example: grep "banana" This is the output Apple banana orange banana lemon melon banana grapes apple banana I want to become: ...
0
votes
1answer
57 views

What does 'history | grep cp -r ' do?

I typed this commands by mistake in my shell and then my shell was filled with all the text . I don't know what it does .Please someone explain it to me .
1
vote
1answer
168 views

Using 'grep' and other utilities

I know this is a seemingly peculiar question, but I want to have a better understanding of using Linux utilities so I'm going to ask for something that seems rather complicated to me to understand the ...
0
votes
0answers
55 views

How to dump selected iwconfig outputs to text files? (to analyse Tx-power, bit rate, link quality, etc. for EMF reduction)

BACKGROUND I've read about Electromagnetic Field (EMF) pollution and I want to protect myself. I have a not bad solution for my smartphone, now decided to tackle WiFi. It appears that power of the ...
0
votes
2answers
65 views

When using grep on html files, how can I display only the text and not the tags?

I have wgot a large website. Rather than setting up a local search engine I use grep to search the site. Grep's output shows the html (of course), but I only want to see the text (and not all the html ...
4
votes
2answers
164 views

Remove all English text and leave Arabic text

This question is a lot like this. I just need a slight modification. I have a csv file that looks like this y(document).ready(function($) { $('#wp_mep_2').mediaelementplayer({ m:1 ...
0
votes
1answer
64 views

Killing every root process over a certain pid

I want to kill every process that is root and not mine. Now there's: sudo pkill -u root But... Well, it kind of, I don't know, MAKES THE WHOLE COMPUTER TO CRASH. So, I need a way to kill every root ...
1
vote
1answer
295 views

cat vs grep vs awk command get the file content which one is more efficient and less time consuming?

Lets say I have file content like this: this is a simple file for testing purpose with few lines in it. to check the cat and grep command to verfy which is best and less excution time consuming ...
0
votes
1answer
21 views

Using grep with regex

I have a regex which works fine for me. I checked it on following site: https://www.regex101.com/ (?<=.log:)[^;]* Unfortunately it doesn't work anymore when I try to use it with grep. I try to ...
1
vote
1answer
250 views

What does grep line buffering do?

Here's my command that I'm using in a script to grep real-time data. It doesn't seem to pull real-time data correctly as it just misses some lines. tail -f <file> | fgrep "string" | sed ...
0
votes
2answers
65 views

Using Grep to search for multiple words in a file

I want to use grep in an If statement to search for a first-name and last-name within a text file. I can't seem to make it work on my own. if [[ grep -E "$first|$last" Datafile.txt ]] then ...
0
votes
2answers
65 views

problem with grep

I was wondering why I get the following output when searching for files with the command: $ grep -l prac * allprac grep: Desktop: Is a directory grep: Documents: Is a directory grep: Downloads: Is a ...
1
vote
4answers
68 views

Using grep to print line numbers

I would like to use the grep command to print a line number for the string I'm searching for. However, when I used the command grep -n it prints the line number with a colon : next to it. Is there ...
0
votes
1answer
83 views

How to create the vertical line [Pipe]

I am new to Ubuntu and i want to know how to create the vertical line that's Pipe in ubuntu 14.10
0
votes
1answer
64 views

Trying to organize files by extension using a script (grep, for, foreach, find), but I'm overwhelmed. Looking for advice [duplicate]

I want to iterate through all files in the Source directory and stick them into the Dest directory. Example list of files: /source/folder/text.txt /source/folder/document.pdf ...
0
votes
2answers
167 views

grep to get compile error

I have created a simple c program and have left off a ';' on purpose to get an error. I want using the grep command to know whether the compilation was successful or not. I use: gcc test.c | grep ...
2
votes
1answer
3k 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. How ...
0
votes
1answer
37 views

Grep for specfic number format

I have a Unix script, which within has release numbers which are like this (2.19.0.32) Look like IP's but are not as some are like this 2.23.0.06.DBP. I've tried variations of this but comes back ...
7
votes
3answers
637 views

How to grep lines, based on a certain pattern?

Let's say I have a file containing following two lines: 2014-05-05 09:11:53 /aa/bbbb/cccccc 29899 2014-05-05 09:12:17 /aa/bbbb/cccccc?dddddddd 16767 I need to get ...
4
votes
4answers
1k views

How to find all patterns between two characters?

I'm trying to find all patterns between a pair of double quotes. Let say I have a file with contents look like as following: first matched is "One". the second is here"Two " and here are in second ...
1
vote
1answer
34 views

'Grotty' man page messages

If I try to search within certain man pages using grep, I get several 'grotty' messages. For example: man mpv | grep dvdnav results in: mpv dvdnav://[longest|menu|title][/device] [options] ...
1
vote
2answers
315 views

grep recursively for specific files

I tried to use grep to find some code snippets in python files which are spreaded over some directories / subdirectories, but unfortunately my attempts failed :( I thought: grep -r "search-pattern" ...
0
votes
1answer
71 views

Locate two variable strings and write one as a file [closed]

I have a text document that contains 2 lines of information. Line 1 contains a filename, and line 2 contains an reference ID. The document contains additional strings other than the desired ...
1
vote
2answers
2k views

How to grep for groups of n digits, but no more than n?

I'm learning Linux, and I have a challenge that I seem to fail to solve on my own. Here it is: grep a line from a file which contains 4 numbers in a row but not more than 4. I'm not sure how to ...