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

learn more… | top users | synonyms

2
votes
7answers
480 views

Remove duplicated dots from file name

I have a dir with tons of files inside which have been named in malformed such as file..txt ,file2..txt ,etc... So how to easily remove this second . from file names? Any applicable method is ...
1
vote
0answers
32 views

Different results of 'ps aux | grep x' if entered manually and done via script

It was probably a bad method, but I was running ps aux | grep x | wc -l as part of the if statement in a script. When I ran this from the command line as a regular user, the result would be 1 if the ...
1
vote
4answers
207 views

Grep showing file name and string found

I need an egrep command that list all the file names that contains the words + which string it has found. Let's imagine this scenario: Words that I need to find: apple, watermelon and banana. What I ...
1
vote
1answer
59 views

diffrence between two files of different row numbers

Yesterday I asked this question, and got awesome answers, it's really a joy to ask questions on this site. Today I got a slightly different question say I have csv1 1,2,3,4 5,6,7,8 -- 9,10,11,12 ...
0
votes
1answer
21 views

grep limit output number with context

If I want to find a line in file and display the surrounding context I use grep -C. If I also want to limit output to the first few occurrences I add -m parameter The problem is that grep just ...
0
votes
4answers
47 views

Adding a number to a already present variable sed/grep/awk

I have this in file.txt FORM: lookupfile Version: 1 LookupFile:"$i" How can I find this in the file and add a variable b to the $i. So example INPUT FORM: ...
9
votes
5answers
645 views

Difference of two big files

I have "test1.csv" and it contains 200,400,600,800 100,300,500,700 50,25,125,310 and test2.csv and it contains 100,4,2,1,7 200,400,600,800 21,22,23,24,25 50,25,125,310 50,25,700,5 now diff ...
4
votes
6answers
445 views

Grep beginning of line

I have a file with the following contents: (((jfojfojeojfow // hellow_rld (((jfojfojeojfow // hellow_rld How can I extract every line that starts with a parenthesis?
-2
votes
4answers
59 views

Copy a string occurring before a particular pattern.

I am to copy this emuEventTrapInformative from below. -- Traps emuEventTrapInformative TRAP-TYPE ENTERPRISE compaq VARIABLES { scellNameDateTime, shelfId, ...
2
votes
3answers
57 views

Delete multiple lines from file when text is found

I've seen multiple answers to delete a single line with sed or grep, but I'm in need to search for a line, delete that one, and the 2 proceeding lines. For example, in the file ~/.profile I have lines ...
0
votes
3answers
50 views

Print a string a number of times [closed]

I have a variable numvar which contains a number. CODE something that reads number stored in numvar and then creates the same number of sTrapValue[with a number here that incrementally ...
-2
votes
2answers
62 views

Delete lines between 2 strings

I am to delete all stings from starting of file to a certain point using anything, sed, Grep, awk in shell INPUT sCSISmart20 TRAP-TYPE ENTERPRISE cyclone ...
2
votes
5answers
108 views

Condition that matches all occurrences of a word in a file ad does something

I am to do something like this for (( every occurrence of the word TRAP-TYPE in a file )) do desc="$(< inputfile awk '/DESCRIPTION/ {getline; gsub(/^\s*"/, ""); gsub(/"\s*$/, ""); print}')" ...
-1
votes
2answers
114 views

Copying some parts of file

I am to copy "SNMP Agent is up" and "::=101" and count the number of variables present (example here there are 5) and put them in 3 Different variables. FROM FILE.TXT sCSISmart1 TRAP-TYPE ...
3
votes
5answers
201 views

sed remove last 2 numerals

I have the following. oid=.1.3.6.1.4.1.795.2.5.0.xxx (these 0.xxx represent any random numeral) I want to do the following echo $oid | sed (some commands to remove 0.xxx) and store the resulting ...
2
votes
3answers
206 views

How to delete lines starting with certain strings

Is there a way to delete lines starting with certain strings. I have this youtube-dl code youtube-dl --extract-audio --audio-quality 0 --newline --audio-format mp3 ...
1
vote
2answers
46 views

Copy particular text from one file to other using GREP or SED

I am to copy the number 795, and use it another file. This 795 could be any number and can change from file to file. Everything till the enterprises will remain the same even the ending curly ...
1
vote
2answers
20 views

find service using grep

I am trying to find specific service and I have question about this command: service --status-all | grep worker Why did service --status-all | grep ... not work?
3
votes
2answers
263 views

Get specific PID and save to file

I'm running two minecraft servers on my machine. I want to know what the pid is of a single mc server that is running and put it to file so that I can kill it later. So for this example I only want to ...
0
votes
3answers
53 views

Grep for a pattern in line

How can i grep for a specific pattern of numbers like 1000010000000 in a whole file - the line has to have thes numbers at the beginning not somewhere else...
1
vote
4answers
171 views

Find text file containing a given text ignoring new lines and spaces?

I have a string like: "thisissometext". I want to find all text files inside a given directory (recursively) that containg this string, or any variations of it with white spaces and/or newlines in the ...
3
votes
2answers
64 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
41 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
43 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
23 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
55 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
38 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
380 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
56 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
50 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
63 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
86 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
152 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
83 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
275 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
52 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
433 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
339 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
32 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 ...
6
votes
4answers
2k 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
43 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
287 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
158 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 ...
-1
votes
1answer
666 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
17 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
56 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
200 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
87 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
66 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
170 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 ...