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

learn more… | top users | synonyms

3
votes
1answer
19 views

grep output of cdrecord

I would like to parse the output of cdrecord/wodim using grep. cdrecord -v outputs lines like Track 01: 49 of 75 MB written (fifo 100%) [buf 100%] 10.2x. The problem is that cdrecord uses ...
1
vote
3answers
106 views

Finding and removing words beginning / ending with numbers

I have a large file (>10000 lines) that contains one word per line, with a newline character after each word. The words contain no spaces. I'd like to list (or even better, output to a new file) any ...
-2
votes
2answers
30 views

Grep contains 'this' but can't contain 'this' into a file

I'm currently working on a homework assignment and it is basically saying, "Find the single line with "Ju" but does not contain the letter "w" in that line" I believe that I have to use grep. However ...
-1
votes
3answers
29 views

Using grep to remove comments from a file

I'm trying to use grep to remove the comments from a file, smb.conf to be specific, and bash is giving me an error. I found this question How to remove all comments from a file? that gives the syntax ...
0
votes
3answers
34 views

How to search multiple Pattern in grep while ignoring the first pattern if appearing consecutively

I have an input like below. I want to find out everything starting with abc and ending with mno including lines in between but if abc appears again before mno comes, then I want to ignore the first ...
0
votes
2answers
30 views

How do I search a directory of data files and print out how many times a certain word appears in each file?

This is what I currently have, however it prints the total number of times Author appears in all of the files: 128367 grep -roh 'Author' $1 | wc -w However how do I print out the word count for ...
1
vote
1answer
45 views

Combining strings command and grep: how to limit results to null-terminated strings

I have a feeling that it is strings which is thwarting my efforts here. The binary files I want to use strings on unfortunately yield several matches per file, even though it is a 100% rule that ...
2
votes
4answers
622 views

The wc -w command outputs incorrect answer [duplicate]

I have to find how many times the word shell is used in a file. I used grep "shell" test.txt | wc -w in order to count how many times that word has been used, but the result comes out 4 instead of 3. ...
0
votes
1answer
19 views

delete line that contains a case insensitive match

I have a file that contains information as so: 20 BaDDOg 31 baddog 42 badCAT 43 goodDoG 44 GOODcAT and I want to delete all lines that contain the word dog. This is my desired ...
-2
votes
1answer
9 views

linux on aix dont work pgrep -lf ora_pmon

pgrep -lf ora_pmon ksh: pgrep: not found. somebody know who to change the code without pgrep this is the result on another Os pgrep -lf ora_pmon 4104 ora_pmon_dbpicsr 5092 ora_pmon_dbpiss2r 14393 ...
1
vote
1answer
35 views

Linux + capture only the IP's from mount command

please advise how I can to print only the list of the IP's ( in the end of the lines ) , from mount output mount netapp64:/lunggg/OracleTeam/OracleCDs on /oracds type nfs ...
1
vote
5answers
239 views

Grep value from json file

my json file looks something like this [{"product":"Apple","id":"2134"},{"product":"Mango","id":"4567"}] I want to grep/sed/awk 'id' for given 'product'. Output: Enter product : Apple Your ...
0
votes
0answers
42 views

Unix scripting : Writing to another file with “:” is failing

I have below record (and many other such records) in one file 9460 xyz abc (lmn):1027739543798. Taxpayer's identification number (INN): 123. For all IIB. 2016/02/03 I need to search ...
1
vote
2answers
16 views

grep to search error_log and email only when results found?

Is it possible to use Grep to search a file and send a email based on the results? I have been using grep SEARCHSTRING /logs/error_log | mailx -s subject name@emailaddress.co.uk But I don't want ...
2
votes
1answer
19 views

grep awk or sed a CSV Row containing a certain part of a web address

I am trying to clean up a Squid log file and I want to delete rows with a website containing "/0/" in the 11th column. An example: Row1: column1, column2, column3...column10, ...
0
votes
4answers
55 views

grep match multiple substrings and pass or fail on missing

I have a nginx -V 2>&1 | \ grep -qi 'nginx/1.9.10\|ngx_pagespeed-release-1.9.32.10\|openssl-1.0.2f\|modsecurity-2.9.‌​0' \ && echo "has the stuff we need" \ || echo "missing ...
-4
votes
0answers
28 views

Finding Parent of a path in Unix [closed]

I have a query of: $unix_linux/stack_overflow/20160201 This is a sample file name. Is there a way to find its parent? I tried . find but I want to find this specific folder for this date. Not a list ...
2
votes
5answers
480 views

ls | grep works doesn't work with ls --color

I'm trying to list all hidden dirs with the following command ls -lhAF1 | grep -E '^d.*[0-9]{2}:[0-9]{2} \.' which works perfectly fine Explanation for Regex: I'm trying to get all rows that ...
0
votes
4answers
34 views

Run multiple piped grep commands from a list in bash

As part of my security job, I analyze dozens of Google Chrome history files each day using sqlite3 over SSH. There are a few dozen authorized "safe" sites each user is allowed to navigate to. For my ...
3
votes
3answers
135 views

Retrieving lines from a file depending on other lines

Imagine the following file structure: foo.bar.1 blabla moreblabla relevant=yes foo.bar.2 relevant=no foo.bar.3 blablabla foo.bar.4 relevant=yes I want to retrieve all foo.bar lines where within the ...
0
votes
1answer
80 views

How do I grep the lines based on '.' (dot)? [duplicate]

Suppose I've file with the following contents: 123 251 7.8 951 Now I want to grep the lines having . I've tried: $ cat file | grep . 123 251 7.8 951 $ cat file | grep '.' 123 251 7.8 951 But ...
0
votes
1answer
17 views

grep -E with parameter doesn't work

If I use -E option for grep from a script I'm unable to user variables. For example: txt file: word nir asd b asd text script: #!/bin/bash PARAM=b cat txt | grep -E 'nir.*${PARAM}' The script ...
-1
votes
2answers
38 views

Grep expression with spaces - BASH

I would like to grep ACCEPT, DROP, REJECT as is shown below. -P INPUT ACCEPT -P OUTPUT DROP -P FORWARD REJECT I executed iptables -S | grep -E '\-P INPUT|\-P OUTPUT|\-P FORWARD' | awk '{print $2}' ...
0
votes
1answer
29 views

Why does piping filenames into VIM break bash when I return to the shell?

I searched for a few files with find and I wanted to open all of them in tabs in Vim. So I tried this: find . | xargs fgrep -l myExpression | xargs vim -p This worked great, except when I was done ...
0
votes
2answers
93 views

What does this command mean?

lines=$(grep '^[^:]\+::' /etc /shadow) What does this whole command mean? What does '^[^:]\+::' mean? if I put if else statement like: if [ "$lines" == "" ]; then Will it display (which is ...
0
votes
2answers
37 views

getting a list of all lowercase words in a file

I'm trying to get a list of all lowercase words in a file. This far I've gotten to the point of getting a list with the command line cat filename.txt | tr ' ' \\n | grep -w '[[:lower:]]*' | sort -u | ...
-1
votes
2answers
38 views

How to indent grep's output? [duplicate]

I need grep's output to be indented with tabs/spaces. This is the plain, un-indented version: MyCmd | grep "id:" I tried this without success:MyCmd | grep "id:" | echo " "
3
votes
2answers
63 views

What does “if echo $line | grep -F = &>/dev/null” do?

I'm not sure what the following line does in a bash script: if echo $line | grep -F = &>/dev/null then ... I know &>/dev/null is short for >/dev/null 2>&1, I'm not sure, ...
0
votes
2answers
70 views

Grep / awk on multiple files to single output

I have several txt-files containing data, where i use grep to search for a current string of text, and use awk to filter out the variable i need. The string is repeated through the file, so i ...
0
votes
4answers
43 views

grep all the lines in a file and write line to a file from the pattern matching point

For example, a temp.txt file contains information like below: adsf on line jhkjhvjdbvjvbvbdjkvn qerwtt on line fdgdgdgdd qwqertg on line safffasffaf wrt on line adaddsd I want to grep for ...
0
votes
3answers
50 views

piping with grep

I want to search "C" in the grades column inside the file "input.csv": roll,name,total,rank,grade 001,A B,78,23,C 003,F YZ,100,1,* and what I'm trying is: cut -d"," -f4 input.csv | grep "C" ...
0
votes
1answer
28 views

live tail (tail -f) of file being grepped

i can do tail -f -n20 <file> to see the last 20 lines of the file, live. If i want to grep something, tail -f <file> | grep <pattern>, it will still be live, but will only grep ...
1
vote
2answers
13 views

Compare 2nd column of the 1st file and 1st column of the 2nd file and print the matched records of the 1st file

I have two files large files: f1.txt: 5020118359 |13ZJ24001218 |20141224|R 5020120475 |13ZJ38000813 |20141204|R 5020127431 |13ZJ38001569 ...
0
votes
1answer
37 views

grep for numbers over 10

I'm looking through a file for specific kernels. I want everything from 3.8. to 3.17. egrep 3.[8-17] is kind of the thing I want but that obviously doesn't work. How do I grep using the example ...
1
vote
5answers
263 views

To remove extra space from line using shell command

This is my file, TLRUIDA CBdms Status DP 6/1/1 DC 6/1/5 0 Y TLRUIDA CBdms Status DP 6/2/1 DC 6/2/5 0 Y TLRUIDA CBdms Status ...
3
votes
2answers
30 views

How to grep a log file from specific date to end of file?

I am looking to grep an Apache access_log file from a specific date/time to the end of the file, so for example I want to grep from the first match of the following string to the end of the file: ...
-2
votes
0answers
21 views

Complex sed Command for Insert Command [migrated]

I have a bunch of php files which have many insert commands. In each query i want to insert a coloumn variable admin_id = '$admin_id' i.e. if the query is insert into users (ch_id, num_value) values ...
3
votes
1answer
14 views

Searching for specific user group membership with an exact match

A user has multiple group memberships that contain spaces. Example: mydomain\staff mydomain\staff admin mydomain\staff super User groups can be returned using: id -Gn username | grep -i -o ...
1
vote
1answer
31 views

Estimate time spent on Git project with grep

Consider a Git log: commit 4d6b30238fbfc972ea4505cadf43abd316506d9e Author: Dotan Cohen <dotancohen@foobar.com> Date: Mon Jan 11 22:41:21 2016 +0200 Final foobar version commit ...
0
votes
1answer
27 views

How to select lines in a file that contain a number from a list of numbers

I have a text file, file.dat, with a number of columns separated by a space. There are some numbers in the second column. I have another text file, select.dat with a list of numbers. I'd like to ...
2
votes
2answers
38 views

How to append string with dash?

I am trying to append create a string that will be evaluated in the middle of a grep line. It is to find possible occurrences of different usernames within a certain file. However, I do not know how ...
1
vote
1answer
21 views

cshell alias: How to use nested single quotes(') in in cshell alias

I am trying below alias in cshell: alias sll 'ls -l \!* | grep -oE '[^ ]+$' | paste -s | xargs ls -l' For this CSH says, Illegal variable name. If I use \$, alias will be set without any error. ...
2
votes
2answers
40 views

Autocomplete from grep output

How might I more easily use a filename found by grep as an argument to vim: $ grep -r foo * lib/beatles/john.c lib/pantera/phil.c lib/pinkfloyd/roger.c lib/pinkfloyd/richard.c ...
1
vote
1answer
32 views

grep content between two starting bracket

Below is file output that I want to access [1] RsyncCommand: 0 Number of files: 18 Number of files transferred: 0 Total file size: 24.01M bytes Total transferred file size: 0 bytes Literal data: 0 ...
0
votes
0answers
12 views

How to take lines containing a particular string tag from a text file and add then to another text file?

I have a large text file with some data that I need and a lot of data that I don't need. The data that I need has a string tag at the beginning of the line followed by a numerical value which I need. ...
5
votes
6answers
176 views

Take grep value and output the count and the value together

I am trying to make a bash script that greps value and output the count and the value together Something like this grep -c 'Thenis' example.txt > example.lst But in that list file not only to ...
5
votes
1answer
54 views

Behavior of grep -o on OSX

On Linux, when I do echo foo | grep -o '^.' to get the first character, it prints f as expected. (I know, | cut -c1 would probably be faster.) But on OSX, doing the same results in 3 matches (3 ...
4
votes
1answer
156 views

grep of top output yields funny characters upon redirection to file

I am running CentOS 6 and I am trying to grep the output of top and redirect it to a file. I.e. top -u user1 -n 1 | /bin/grep somecommand &> scratch.txt The output of vim scratch.txt is ...
0
votes
2answers
72 views

Parsing HTTP response with shell

I want to parse below HTTP response but I cannot figure out how to grep the values separately using a single curl request. I need these two output. 1. status_code - (Array of HTTP status codes) 2. ...
1
vote
3answers
58 views

grep a awk string from a file and write to the other part of string file

My file, aaa,has 5 lines. 01_AAA-11-ID22 02_BBB-33-ID44 03_CCC-55-ID66 . . I tried to grep anything after underline from a file bigfile.txt for i in $(cat aaa) do A= $(awk -F '_' '{print $1}' $i) ...