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

learn more… | top users | synonyms

0
votes
2answers
31 views

How can I cut the mac address out of DHCPDUMP?

I am trying to use dhcpdump to recognize people logging onto my home network and give them a tailor made greeting using a credential file. I cannot get the mac address out of the results of dhcpdump. ...
0
votes
1answer
39 views

Using Grep to multiple find and replace

I have lets say 90 HTML files and I have to put one new JS script link to head section each of them. Now, i could use some F&R engine of some code compiler Like: find: </head> replace it ...
0
votes
3answers
51 views

How to search through a man page?

I often want to search through a man page, however I am forced to either do: man <package> | grep <search> Or: man <package> > file.txt But there must be an easier way than ...
0
votes
4answers
53 views

Using grep in /etc/passwd to fetch list of users and system users, discriminating both

I want my grep to print a user list from /etc/passwd, and I've studied /etc/login.defs' minmax values for the ones I want my grep to fetch: # Min/max values for automatic uid selection in useradd # ...
2
votes
2answers
76 views

Why is my repetition condition with grep range not working?

Searched for a solution on SO, Ask and Unix/Linux but I am lost trying to figure out how to write a conditional with a grep range: Go through: 1-20_something 100-200_something 2-100_something ...
0
votes
2answers
32 views

shortening the output from the command ps efo cmd | grep

I want to condition on whether or not a certain process is running. The process has a very long description, more or less like /usr/bin/xpdf -remote myXpdfServer -title Bayes2_notes -papercolor ...
0
votes
2answers
41 views

Extract numbers with awk

a part of a script in awk looks like this sub(/^Mutation: {"seq-pos":/,"") && sub(/, "time":/," ") && sub(/}$/,"") { print >"fifth_"FILENAME} The aim is that given this ...
-2
votes
2answers
108 views

how to search a word or text with in command prompt

For example i have printed a mysql big table from database on cmd which has 500 fields in it .How do i search for a particular word with in command prompt. I know grep is used to search strings or ...
1
vote
2answers
162 views

How to grep for all packages used in a tex file

Assuming I want to grep all packages used in a tex file: $ grep usepackage my.tex will do, with (as far as I can see) one exception: If a package gets loaded with that many options that the author ...
0
votes
1answer
16 views

grep with limited recursion when redirect file exists

I'd like to search a word in all files under a directory recursively, and output the occurrence lines into an output file in the directory. grep -ri "my_str" ./ >> opt_file.txt However, since ...
2
votes
1answer
49 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
183 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
52 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
87 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
32 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
27 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
62 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
67 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
551 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 ...
2
votes
0answers
67 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
339 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
68 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
54 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
52 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
752 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
528 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
69 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
108 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
56 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
72 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
123 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
121 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
281 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
230 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
100 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
26 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
334 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
67 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
358 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
91 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
63 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
50 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
25 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
56 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
52 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
467 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
62 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
87 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
80 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
119 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/ ...