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

learn more… | top users | synonyms

0
votes
4answers
78 views

grep all strings that start with a certain char, and finish with another char

I need to grep all strings that start with "[" and finish with a certain string, e.g. "apal". So all chars in between these 2 chars would be shown as well. Given an input such as: [44060]apal223reaea[...
0
votes
3answers
51 views

Using grep and looking for unique occurrences [duplicate]

I have a text file of this type, and I would look for any lines containing the string Validating Classification and then obtain uniquely the reported errors. I do not know the types of possible errors....
5
votes
3answers
300 views

Grep exact number of digits and some other characters

I'd like to parse a file containing 5 digit numbers separated by comma or dash, lines like : 12345,23456,34567-45678,12345-23456,34567 My goal is to find lines which have incorrect formatting eg. ...
1
vote
1answer
71 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ....
15
votes
2answers
566 views

How do I use grep while keeping the original text color? [duplicate]

For example, I have a output: Hello, this is the output. (let's say that for example hello is colored red, and the is colored green, and output is colored purple). Now, let's say that this is the ...
0
votes
0answers
19 views

check if a variable contains letters and exit if true [duplicate]

I am using the line below to verify that an argument do not have a letter. If it have, the script will exit. Can you help me on how I can exit the script if the argument have a letter? echo $1 | ...
6
votes
4answers
590 views

In grep command, can I change [:digit:] to [0-9]?

Will grep [0-9] work in the same way as grep [:digit:]?
3
votes
3answers
55 views

Grep that works with overlapping patterns

I want to count the number of repeating patterns aa in a very big file. So I use the following command: grep -o "aa" ./bwt/dblp.txt | wc -l This works, except when I have a string such as aaa, ...
0
votes
2answers
71 views

Select rows based on the values of a specific column (not the first column)

I would like to read a file.csv file and keep the rows (i.e., all the columns) of the file if and only if the sixth column of that file matches values in user_ids_to_keep.csv. The file.csv file I ...
2
votes
3answers
62 views

Print up to (and including) the nth occurence of a pattern in a line

Let's say I have multiple lines similar to below in a file. Turbo is a cat. cats are good. cats are not dog. Coco is a black cat. cats are furry. cats are not dog. now, if want to grep all the ^.*...
1
vote
2answers
42 views

Which of the following use of anchor is correct in regex using grep?

Both of the below commands gives the same output, however which one is the correct method to use it? grep ^'\<that\>' file.txt Searches for the line which has that as the first word grep '^\&...
0
votes
1answer
39 views

Awk to get same column with maximum filed

I have two files. I have to get matching name from file1, print the entire content of file1, and add a fourth column (exp) in file 1 using a second file with max value file1 name value1 ...
3
votes
4answers
57 views

Search within a search

I've gotten used to using grep for my command line searches and wanted to know how to successfully do a search using the result of another search. Here's my attempt, where I am looking for 'tool' ...
0
votes
2answers
39 views

Remove lines in a file where pattern only occurs once

I have a CSV file. It is ordered by an identifier the first field. The identifier in the first field can appear in either 1 or in 2 lines in the field. I want to remove all lines in the file where ...
1
vote
1answer
32 views

Boolean Issue for Grep

whois=`whois 100.43.81.149` bool="$(printf %s\\n "$whois" | grep -q netname:)" if $bool; then echo "netname: is available" else ...
0
votes
3answers
19 views

find muli lines in file from other file

i have text file that have multi lines i wanna search for lines containing some text and add # at the start of those lines ex: file1 that i wanna change it acnet 6801/tcp # ...
1
vote
1answer
33 views

How to search recursively within several levels of embedded tar tgz files? [duplicate]

Can somebody help me to figure out a command to find a file recursively that is embedded in a tgz file which is within another tgz files recursively: MainFile.tgz → SubFile1.tgz → SubFile2.tgz → ...
4
votes
4answers
207 views

Count text occurrences per line

I have to parse huge text files where certain lines are of interest and others are not. Within those of interest I have to count the occurrences of a certain keyword. Assumed the file is called input....
0
votes
1answer
45 views

How to make sed as fast as grep when replacing values

If I search with grep in a 30 gig database for some values it finds all of them in no time, if I run the same command with sed to replace those values it takes ages. Why is grep so much faster than ...
0
votes
1answer
31 views

Extract two lines following a line with a specific value

I have a text file and I would like to extract the two lines of data following a line containing only "Name" as a value. Name 032 Express intent to engage in diplomatic cooperation (such ...
2
votes
4answers
674 views

Why does the grep command ignore the period in the search string?

The command that I am using: find . -type f -name "*.sql" -exec grep -i -l 'schema_name.' {} + What I want to search is all the files which contain schema_name.. But the find command is ignoring ...
2
votes
1answer
45 views

Better way to run a series of seven identical commands in sed? [duplicate]

In the post Sed - Replace first k instances of a word in a file, a user suggests: sed 's/old/new/;s/old/new/;s/old/new/;s/old/new/;s/old/new/' filename as a method of replacing the first k ...
2
votes
1answer
41 views

Bash script to summarize “ last -a ”

I would like to make a shell script such that it runs the " last -a " command and summarizes it's data in the form : userID : number of login sessions Host or ip1 - number of ...
2
votes
2answers
90 views

Sorting one file line by line based on another file

I'm trying to sort the rows of a text file based on an 'index' in another file, such that the text file is arranged, row by row, in the same order as the index file. The following code achieves what ...
-3
votes
1answer
39 views

How do i create a sed script to prompt the user to replace a number in a file? [duplicate]

I'm new in Unix, and I'm learning about sed command. I need to write a very small script for searching a number in a file and replacing it. I tried doing grep, and than deleting the specific phone ...
0
votes
2answers
45 views

return first instance of characters from a list

Lets say I have the output of this command saved to a file. cat /dev/urandom | tr -dc '[:graph:]' | fold -w 1000 | perl -pe 's/(.)(?=.*?\1)//g' | head -n 50 I would like to compare only the first n ...
-1
votes
3answers
52 views

How to filter log file for string inside single quotes?

I have a log file, which outputs information this way: 2016-01-01: foo bar fnord 2016-01-01: this is static 'this is of interest' some blob bar 2016-01-01: this is static 'this is of interest' some ...
0
votes
2answers
56 views

Piping sed/grep output does not work

If I run the commands bellow, only out1 has output, the out2 and out3 are empty. # this is just to generate a self-signed certificate openssl genrsa -out /tmp/ssl.key 2048 openssl req -sha256 -new -...
0
votes
3answers
45 views

How can i extract data from this line?

xyz /mnp/opq/p/1926081/sp/192608100/serveFlavor/entryId/0_ffx7sljc/v/2/flavorId/0_,n6h1xlhl,ea3anltg,jfs8boo9,w2v1vsk2,ze8e1q2s,to8w2p18,/forceproxy/true/name/new in this line this part ,n6h1xlhl,...
3
votes
3answers
98 views

Is it possible to use grep lookaroud multiple times?

<table name="content_analyzer" another-key="id9"> <type="global" /> </table> <table name="content_analyzer2" another-key="id12"> <type="global" /> </table> &...
1
vote
1answer
52 views

How do I use multiple options for grep (on live output)?

For example, when I do this sudo tcpdump | grep -E '.dev:8888|ads' | grep -v 'adsl' ALL output is suppressed for some reason, nothing is shown if I access ads.google.com for example, it does show ...
3
votes
1answer
62 views

Filtering the colored output of grep

I'm on OSX, but I suspect this doesn't make a big difference for this question. In my .bash_profile, I aliased grep to get color outputs by default: alias grep='grep --color=always' I commonly run ...
3
votes
3answers
139 views

Add mtime to grep -c output and sort the output by mtime

I have a directory full of logs named in the following style: info.log00001 info.log00002 info.log00003 ... info.log09999 info.log My current output (using grep -c) I need to analyze the ...
1
vote
2answers
67 views

Tar files starting with the same pattern

I have some log files named : 2016-02-10_03-52.log 2016-02-10_04-43.log 2016-02-10_02-13.log ... 2016-03-15_07-03.log 2016-03-15_09-08.log Basically the pattern is : YYYY-MM-DD_.log I would ...
0
votes
1answer
61 views

Compare 1st column of the 1st file and 2nd column of the 2nd file and matching

File1: Excel file (.xls) UN ID St M1 M2 SE DOF PV PA FC 17127159 0 -5.9 297.3 765.7 0.22 4 0.003 0.00389231 2.57536 17127163 2 ...
-1
votes
2answers
24 views

count lines in with 2 words

I have a text file with many lines like - The quick brown fox jumps over the lazy dog The quick brown fox did not jumps over the lazy dog The quick brown fox may jumps over the lazy dog The quick ...
3
votes
1answer
115 views

GNU parallel excessively slow

I need to run grep on a couple of million files. Therefore I tried to speed it up, following the two approaches mentioned here: xargs -P -n and GNU parallel. I tried this on a subset of my files (9026 ...
6
votes
1answer
321 views

grep --exclude does not exclude my file

I am searching a dir for a particular string (to see all instances of where the string is present and in which files). However, I want to exclude one particular file from being searched. Here's what ...
0
votes
2answers
103 views

Curl and Grep to Parsing Content

I need to parse the output of a curl command: curl --user test:test http://192.168.1.1/security/pkm.html | egrep '@company|config.pkm.password' This returns: <input type="text" id="config.pkm....
0
votes
0answers
16 views

Different regex engines and syntax in unix tools like grep, find, vim, sed, aptitude etc [duplicate]

I would like to learn and use regex more. I made couple tutorials and trying use regex in everyday tasks. But I've found thing that demotivates me and slowing learning process - different syntax/...
0
votes
4answers
29 views

Extracting a text backwards from a selected character

I am quite newbie with scripting. I have a file with following lines: handleNewConnection:: User langfordm@system.com has 2 active nodes handleNewConnection:: User bas102@system.com has 2 active ...
0
votes
1answer
50 views

Awk and Grep to get data from CLI

I want to get output as below: Number Name Value ************************************* 889900 Staff 256000 990088 Staff 1048576 And my input would be as below: ...
2
votes
1answer
31 views

Will zgrep recursively search zips embedded within zips?

I am using the zutils version of zgrep v0.9 (not the gzip wrapper script) and to recursively grep zip files starting from the current folder I simply use: zgrep -r "MY_STRING" . This works fine. ...
0
votes
3answers
49 views

How to test which strings from File A are not present in File B, without displaying anything that is present in File B and not in File A?

I have a text file, say sitelist1.txt (File A), that has some URLs like below: http://www.facebook.com http://www.twitter.com http://myspace.com/profile http://orkut.com/archived I have another ...
0
votes
2answers
54 views

Problem with grep -o

I have a text file as shown below. 192.168.10.1 192.168.45.45 192.168.255.255 192.168.0.5 Random text comes here 8.8.8.8 224.23.25.12 225.1.2.3 226.0.0.0 227.1.2....
1
vote
1answer
36 views

Examine a bunch of huge files

I have a folder with big files (few GB each). I would like to search aPATTERNthrough these files. I can do this with grep or ack: $ grep -n 'PATTERN' /path/to/files/*.log Now, I have a list with ...
1
vote
0answers
79 views

Find list items in other file [duplicate]

I have one file with hundreds of unique IP addresses (each on a separate line) from which a bot tries to login to one of our services. I would like to see which of these addresses appear in another ...
1
vote
2answers
33 views

How extract under linux some capturing groups using command line in a php/preg fashion?

Given in linux environment exists lot of packages for manipulating strings (grep, awk, sed, ...), I would like a software to extract a capturing group in a php/preg like syntax. Maybe the most close ...
0
votes
3answers
97 views

Using rpm/grep to check whether multiple services are installed - as one liner?

The following code is used to check whether a service (read from variable, can be empty or up to X services named) is installed or not and take appropriate action. ... if ! rpm -qa | grep -qw $...
0
votes
2answers
63 views

How to get only certain fields from a given file?

I have list of employees in following format Name: Phone No: Email: Name: Address: Phone No: Email: Name: Country: Address: Phone No: Email: Name: Address: Name : Email: Address: All I want ...