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

learn more… | top users | synonyms

0
votes
2answers
48 views

Conditional grepping

I have a scenario to handle. Need help with that... I have a config file and its content looks something like below: Jobname|Type|Silo|Description #comment1 #comment2 ...
2
votes
1answer
28 views

Find value for a given key using grep in the string

How can I grep SSID value from the string below using grep? SSID: Home, BSSID: aa:bb:cc:dd:ee:ff I tried grep -oh "SSID:.*," and other combinations but to no avail. The reluctant ? quantifer ...
3
votes
2answers
32 views

Search in specific column for pattern and output entire line

I'm working in HDFS and am trying to get the entire line where the 4th column starts with the number 5: 100|20151010|K|5001 695|20151010|K|1010 309|20151010|R|5005 410|20151010|K|5001 ...
1
vote
0answers
32 views

Extract coordinates of matching text in PDF

Basically I want to grep a string in a PDF and get the coordinates of the matching result(s). I already use pdftotext to do the opposite, namely to extract some text given its coordinates. In ...
4
votes
5answers
198 views

Print several lines after nth occurence in bash

I'm looking for a way to search for the nth occurrence of a pattern and print k lines after the pattern. I guess awk would work better than grep in this case but I cannot figure out the way to do it ...
1
vote
5answers
109 views

How to use grep to extract file names at end of lines?

I have a log file which contains information such as output using ls *.CCD from directory /var/tmp/Person: -rwxr-xr-x 1 bv90 dkas 153698 Nov 18 13:08 WE994002.CCD I have many such ...
2
votes
3answers
43 views

how to extract a number from the line in unix

I need to find the first occurrence of the attribute ICount and its value must be returned. Only the number from the attribute. How to get it? < FCount = "1" ICount = "0" Ccount= "1"> Please ...
2
votes
1answer
38 views

Grepping and sedding IP from ip addr show

I'm trying to get just the local IP of my Arch VM. I've managed to get just the line containing what I want with grep, but I also want to trim it down with sed. inet <<192.168.0.16>>/24 ...
1
vote
1answer
30 views

Validate a list of xml files

I'd like to validate a list of xml files against a schema, and only be notified of failures. This command seems to work, but the last grep command has no effect: find -iname "*.xml" | xargs xmllint ...
0
votes
2answers
43 views

Find the number of all typed commands which include a string , using grep

I'm searching through my bash history log for all the typed (started) commands which included the string x. For some reason, the homework checker always says that the number I'm giving is bigger than ...
1
vote
2answers
61 views

Grep from a line to a line [duplicate]

I have a file with hounded of thousands lines. I need to grep from a line to another line and include everything between these lines i.e lines from Wed Nov 25 23:08:01 GMT 2015 to Wed Nov 25 ...
2
votes
5answers
145 views

List (or move) only files with a certain number of lines?

Dealing with a whole bunch of two-line config files, I'd like a way to exclude any files that have a different number of lines. So, something like: mv * destdir only if file contains exactly two ...
0
votes
4answers
166 views

How to display output of command while also parsing it?

I have two commands, build and deploy. Currently I run build manually, parse its output using my own eyes, and use a value I find in the output as an argument to deploy. The process looks something ...
1
vote
2answers
48 views

how to grep for packages on basis of uncompressed file-size?

In Debian when you look at a package, you get lot of info. Including the uncompressed file size of the package. Is there a way to grep through the file-listing so that packages appear either from ...
1
vote
1answer
52 views

What does a backslash represent when searching for decimals

I want to understand what the backslash represents in this command. grep "\.900983" table I know what the command does, it searches for the 900983 value in table, I'm just not sure of the purpose of ...
0
votes
4answers
79 views

How to grep the result of a grep?

I need to grep some files to see which ones contain a certain word: grep -l word * Next I need to grep that list of files to see which ones contain a different word. The easy way would probably be ...
0
votes
2answers
31 views

finding how many options ls have

Just for practise i want to find out how many options does ls command have. I have written following piece of code man ls | grep -o -i '\-[a-z0-9]$' Why does this piece of code only printed -C and ...
1
vote
0answers
105 views

Find and delete lines containing multiple patterns in a file

I have a list of strings and want to find and delete lines containing these strings in a file. A short example of the list of strings is listed as below. File S 1Mo 32,33 2Mo 7,26 2Mo 7,27 2Mo 7,28 ...
-5
votes
2answers
61 views

Search word structure using grep

Some English words contain an "abba" structure, such as "tomorrow" or "better". How many lines of a given file contain such a word? How do i search such words using grep?
-2
votes
1answer
84 views

Find vowels using grep command

How do i find three vowels in a row in a given file(not counting Roman numerals as words, and not counting "Y" as a vowel)?
0
votes
0answers
36 views

Finding word with centain length containing characters from interval

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following grep '\<[a-s]\{3\}\>' file.txt which outputs nothing , i have ...
1
vote
1answer
37 views

usage of apostrofe in grep rexExp

I have recently started learning regExp and found nice example of it in shell using grep to extract only anchor tags url e.g <a href="unix.stackexchange.com"></a> grep - 'href="[^"]*"' ...
0
votes
1answer
74 views

Passing a variable argument to egrep in a bash script

I have a script, myScript, which is trying to egrep the script argument in a file. Somehow variable expansion isn't working properly with the egrep command. I believe I've isolated the problem ...
0
votes
1answer
26 views

How to recover a node/content from a tarfile that's been overwritten

Disclaimer: I'm not very good at writing questions, and mine is a very specific scenario. So I'm just going to jump straight into the situation: I was browsing my filesystem, and somehow managed to ...
3
votes
1answer
29 views

grep search for any number in a range

So I have a file with a number of records that look like the following: Peugeot:206:2000:Red:1 And I'm trying to grep search for any that contain a year 1995-1999. I have tried grep '[1995-1999]' ...
1
vote
1answer
38 views

REGEX and GREP — Search string including optional and static words

I am trying to formulate a regex expression for use with grep such that I find a static word present at the beginning of each line, followed by only one word from a list of options. That is, I ...
1
vote
2answers
95 views

Using awk and grep for iftop results

I wanted to monitor my server network send and receive rate using iftop. This is what works for me: iftop -t -s 1 -n -N | grep 'Total send and receive rate: ' | awk '{print $8}' Mac address and Ips ...
1
vote
2answers
45 views

Find values in a file from another file

I know, the title is not clear. I have 2 files, in one of this I have some values and I need to find them in another file. Instead to grep for each single value, I would use the first file to do ...
0
votes
1answer
71 views

GREP - pattern match from file only returning on last pattern in the list

I have a list of about 23 million hashes in a text file, one hash per line. Call it hashes.txt I have a list of nuisance hash values (app 40) in another text file, again one hash per line. Call it ...
2
votes
1answer
40 views

How to use BRE or ERE regex to match a pattern which does not have a specific string

How to use a posix BRE or a posix ERE regex to match a line that doesn't contain 834 at any place in string? I want to find grep '!<pattern>' file which will be equal to grep -v ...
1
vote
3answers
107 views

Match lines beginning with the same pattern in two text files

I am now having two text files with some of the lines beginning with the same pattern. For example, File A 1Mo 1,1 I love you. 1Mo 1,2 I like you. Hi 23,3 I am hungry. Hi 23,4 I am foolish. File ...
0
votes
0answers
17 views

redirect all errors of my script into errors.txt [duplicate]

I need to redirect all errors into other file which called errors.txt this is my script shell : data_in=$1 fichier=$2 cd $data_in #Purge des fichiers rm -f Split/INIT_ENC.dat rm -f ...
1
vote
1answer
38 views

copying and working on OSX .app files (folders) in linux

tldr; I want to run a script over an external hard drive and tar.gz every folder that ends with .app into their own archive. That is, I don't want them all in one tar.gz file, I want to create one ...
2
votes
5answers
158 views

How can I list the names of directories that contain files matching a regex?

Given a directory X that contains several subdirectories and files, I would like to list the names of the immediate child directories of X that (directly or indirectly) contain files matching the ...
2
votes
6answers
220 views

Extracting IP address from a text and store it in a variable

I have a text file named abd shown below. 48878 128.206.6.136 34782 128.206.6.137 12817 23.234.22.106 I want to extract only IP address from the text and store it in a variable and use for other ...
1
vote
1answer
68 views

How to find all files containing a specific string recursively on a BusyBox 1.4.2?

How to find all files containing a specific string within directory and all subdirectories on a BusyBox v1.4.2? I need to find string "AA:CC:DD:00:EE:55" or "AACCDD00EE55" BusyBox v1.4.2 (2012-06-01 ...
2
votes
1answer
68 views

bash regex: asterisk gives ambiguous search results with grep

I am using a simple text file to test the * meta-character through grep. The text file is as below: 1 11 111 1111 11111 111111 d da daa daaa b bc bcc bccc Now when I search digit 1 using grep ...
1
vote
3answers
89 views

How to grep all words starting with digit?

I am wondering how to grep all words starting with digit. So far, I have made this: egrep "^[[:digit:]]" tst But it prints me just a lines starting with digit. Thanks in advance with help.
3
votes
5answers
314 views

Search files for a string and if found check if a file with paired name exists in the same directory

I have many different files with the same ending .ft1 that may or may not contain one specific word special. For the files that contain this word, I want to check whether another file with a different ...
2
votes
2answers
119 views

grep -E-f to capture matching ip-addresses in two files, and , print or echo result of each iteration, xx.xx.xx.xx found or xx.xx.xx.xx not found

Having one short list of few hundred ip addresses in file1, and want to identify if any of these ip addresses are missing from the master list, file2. Looking for an output > redirect to a file that ...
0
votes
1answer
18 views

'or' condition in grep -E

1)ovs-ofctl show br-int | grep "qvo\|tap" | awk '{print $1}' | grep -E "5.tap" The above(1) works fine, but if I include 'or' with grep -E like below command, I'm not getting any output. 2) ...
2
votes
2answers
41 views

How to escape metacharacters for egrep like metaquote from Perl?

Perl has a function called metaquote() to escape all special characters for a regular expression. Is there an equivalent technique for egrep? Example: If I am searching for the string abc.def.ghi, I ...
2
votes
1answer
60 views

Using sed / awk to change words between two patterns

I'm writting the shell script that should process through some text, I've got the text like that: read build { file1 file2 file3 } check build { file2 file3 file4 } read build { file4 file5 file6 } ...
1
vote
2answers
40 views

Help with regular expression in grep

someone can explain me why this regexp doesn't work in grep? ls -la ./ | grep -E '^d.*\<\..*\>$' In my (wrong) opinion this have to show me the line of the directory with a name that start ...
1
vote
1answer
63 views

Calculate max TPS from log file

I have this bash script to compute the max tps from an application's log file. The script works but it takes several hours to run on files with millions of entries. The log entries have the following ...
1
vote
3answers
252 views

How to extract XML from a text file

I have a text file as below. 1001=<?xml ns=dkfj><home><taga>dkjf</taga></home>1002=<?xml ns=dkfj><home1><taga>dkjf</taga></home1> I need ...
1
vote
1answer
30 views

display users that logged in since a date using last

I am trying to display the user name of the accounts that have logged in during the past month using the last command. At the moment I have this last | awk '{print $1, $4 ,$5 ,$6}' | grep -B 10 Jul ...
1
vote
1answer
30 views

Search for file in folder1 and execute a script if that file isn't in folder2

folder1 contains only .flv files. folder2 contains only .mp4 files. All .flv files in folder1 SHOULD have a corresponding file ending in .mp4 in folder2 : /folder1/123.flv and /folder2/123.mp4. I ...
3
votes
3answers
52 views

Filter a list of files based on file attributes

With find you can search by file attributes like -type, -executable etc. How to achieve something similar, but from an existing list of files? e.g. the output of dpkg -L <package_name>. A pipe ...
0
votes
2answers
54 views

Problems with regex in grep

I'm trying to remove malware code from a site using a script, I'm having trouble getting the regex right for the malware part. What I want to do eventually is to use sed in order to find the ...