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

learn more… | top users | synonyms

2
votes
1answer
31 views

watch cuts off ps aux output when piped

While working on a (Python) script which is of no consequence here, I have come across a very strange behavior involving watch and ps aux, when the latter is piped to something else. I have managed ...
2
votes
1answer
128 views

How to mark matching GREP string while redirecting output to file

I am trying to use grep to find all matching strings in file and output them, in context of the line, to another file, while adding some kind of marks (ideally two asterisks) on each side of the ...
0
votes
1answer
36 views

Filter consecutive identical characters using Sed and grep

How to find the occurrence of three consecutive and identical word characters for example aaa, bbb etc using sed and grep
2
votes
2answers
57 views

Filter lines based on length using sed and grep

How to locate lines longer than 100 and smaller than 150 characters using sed and grep
1
vote
2answers
25 views

Extracting strings from mail log

I'm trying to extract all lines of text from mail log file that contain specific string (mail address). I know using grep will allow me to search for the address mail.addres@example.org, but how do I ...
0
votes
1answer
26 views

Deleting an embedded string in a text file with grep or anything else via terminal

I have a text file and would like to remove '/d0/' '/d1/' ... '/d5/' from the each line of text. I know I can ls the files with '/d*/'. I figure it is grep -vE '//d*// filename > filename ...
2
votes
2answers
58 views

Shell Programming using sed to delete a line from txt file

I want to remove a line from a .txt file using the grep and sed functions but the output I get does not alter any of my info in the text file. Any suggestions on how to get the desired output? Thank ...
0
votes
3answers
44 views

Script to extract text using grep

I am trying to extract two text strings from multiple data files in a directory. I want to separate the text string using a ~ character and send the output to one single file. Example directory name: ...
1
vote
7answers
531 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
52 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
268 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
64 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
35 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
49 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: ...
10
votes
5answers
698 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 ...
5
votes
6answers
473 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
65 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
76 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
52 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
68 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
115 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
118 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
238 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
218 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
71 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
23 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
290 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
60 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
243 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
77 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
51 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
47 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
24 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
44 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
417 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
59 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
62 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
73 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
100 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
195 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
91 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
291 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
61 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
634 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
357 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
4k 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
51 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
640 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. ...