Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [grep]

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

0
votes
1answer
13 views

grep on remote machine

I have a template file with content count : 2 ssh ubuntu@ip << EOF cat template|grep count|awk -F":" '{print $2}' > log EOF Desired output is 2 but it's printing count : 2
0
votes
3answers
18 views

Can I grep/awk/sed a line for multiple matches in a single line and get the info after it?

I get files that come in from an external source that are unordered... and contain bits of info I'm interested in and some that I'm not. name: myName var1: xxx var2: bbbb var1: xxx var2: aaaa name: ...
0
votes
2answers
27 views

find a word/string that contains a q and not followed by a u

I'm looking to find a grep command to search for all words/string that contain the letter q that is not followed by a u directly after. grep 'q!u' file
0
votes
1answer
16 views

grep pattern syntax for finding words

I'm trying to find all words in which my initials show up not necessarily consecutively. My first initial should start the word. My last initial should end the word. My middle initial is somewhere ...
-2
votes
0answers
40 views

Need way to grep through files for malware

I am running into a lot of issues with some files being infected, however, I figured they are very similar code inside and I was thinking about grep-ing through files to find this snip of code. The ...
1
vote
1answer
34 views

Better more efficient bash script (grep)

I have a script that I built .. And it works fantastically -- BUT it's going to take an estimated 4 days to run! I was wondering if there's a more efficient way of doing this. Here's what the ...
0
votes
4answers
72 views

Need identical lines from file2 which are present in file1

File1 contains numbers each per line (0 to 9 digit length) total records 20k File2 contains numbers(0 to 9 digit) in first column and other info in each line,total recs 46 ,000,00 Both files are ...
1
vote
1answer
15 views

The “perfect” egrep in a file with a lot of garbage and one huge line only

I have a file with a lot of garbage(strange chars,comments,etc),the file contain some links which I want to extract with grep. File is really big,over 2000 words in one line. If I try this line works ...
7
votes
7answers
507 views

Grepping string, but include all non-blank lines following each grep match

Consider the following toy example: this is a line this line contains FOO this line is not blank This line also contains FOO Some random text This line contains FOO too Not blank Also not blank ...
0
votes
1answer
27 views

single long line searching

I have a large document that is only 1 line, it spans multiple pages of vi. Below is an extract of a small bit, I'm seeking to show text after aria-label=" I would then like to stop at aria-...
-1
votes
1answer
48 views

How to grep for a particular string?

I am trying to get a string that matches the following pattern: starts with foo and finishes with bar. grep -e "^foo*bar$"
4
votes
3answers
260 views

Extract substring according to regexp with sed or grep

In a (BSD) UNIX environment, I would like to capture a specific substring using a regular expression. Assume that the dmesg command output would include the following line: pass2: <Marvell ...
0
votes
1answer
34 views

bash script to replace script tags in html with their content

is it possible to use sed to match the source of a script tag within html (which is not valid xml) and replace the whole match with the files' contents? e.g. say the html contained <link rel='...
0
votes
1answer
35 views

find: './proc/1/map_files': Permission denied

I am inside a docker container build atop of the image alpine:3.6 and I am trying to find if a directory exists. I get te error, find: './proc/1/map_files': Permission denied This is the commands I ...
0
votes
1answer
23 views

How to extract the URL from xml or any text file

My XML file; <settings version="2"> <setting id="TimeShift" default="true">0</setting> <setting id="Override" default="true">false</setting> <setting id="...
0
votes
4answers
18 views

How to grep with multiple filters and print one by one?

I need count some patterns in logs, I can use grep aaa ./logs | wc -l grep bbb ./logs | wc -l is there a easy way to do all things in one line? like cat ./logs | grep -c aaa | grep -c bbb #didn't ...
1
vote
4answers
42 views

Get a specific words from a specific line from a text file in NetBSD

How does one proceed to extract member names from a list like the one below and output them to a new file? Group-name supernatural Members admin, Admin1, John, sam, dean Group-id 405 expected out-...
-2
votes
1answer
34 views

grep routing table & execute command

I'm trying to make a script on my Linux machine that will grep for a specific routing in my routing table and execute command depends on the find. This is what I have so far and it's not working: #!/...
0
votes
2answers
44 views

Grep in bash issues

Sample string: --000000000000f104a6057d4a0a10 Here I need to get for sure: "--" Same files also contain a lot of similar strings; ------=_, --=_ , -----------, --< which currently also get ...
0
votes
2answers
42 views

Grep doesn't work when trying to match a word from a file in a second file

I've got 2 files, both with numerous lines that only contain one number. I'm trying to see if any number from file1 matches a number in file2. This is what I tried, and for some reason it doesn't work:...
1
vote
1answer
39 views

Grep to find a word matching a specific pattern and ignore accents

This is a homework question that I have only been able to partially solve. I want to use grep to find words in a list that contain three 'e's separated by 't's, and also do an accent insensitive ...
1
vote
1answer
36 views

How to get the position of LUKS header by `bgrep`

I tried to get the position of LUKS header: grep -a -b -P --only-matching 'LUKS\xba\xbe' /dev/sdb It is out of memory. Some sugest me use 'bgrep' instead, but I don't how to make it work. bgrep -A ...
2
votes
4answers
210 views

How to copy the rest of lines of a file to another file [duplicate]

I have the string xyz which is a line in file1.txt, I want to copy all the lines after xyz in file1.txt to a new file file2.txt. How can I achieve this? I know about cat command. But how to specify ...
1
vote
1answer
37 views

How to parse openssl certificate output into hostname and verification codes?

I have this shell code that reads lines of host names from input file, performs an openssl command to print ssl certificate info, and outputs the results in the terminal. while read x; do echo $x; ...
4
votes
2answers
291 views

Searching for a string that contains the file name

I have a large set of files in a directory. The files contains arbitrary text. I want to search for the file name inside that particular file text. To clarify, I have file1.py.txt (yeas, two dots .py....
0
votes
1answer
41 views

How to grep exact text using input as a file?

command used is : grep -f <input_file> <dump_file> Example : Input_file contains following apple banana dump_file contains apple banana apple_fruit banana_fruit Objective is to ...
-1
votes
3answers
48 views

grep + FIND all files that are jar files and ended with jar [closed]

With this way we can get all .jar files list: # su -l hdfs -c " hdfs dfs -ls /home/test/jt/*.jar " -rw-r--r-- 3 hdfs hdfs 501879 2019-03-04 10:35 /home/test/jt/cfjrfr-3.8.1.jar -rw-r--r-- 3 ...
-3
votes
1answer
47 views

List files not owned by root at the / directory

The actual homework question is List all files/directories NOT owned by root and not created in July. I can't find a way to use ls and grep to output a file ~/NotOwnedByRoot.txt find / \!...
0
votes
4answers
88 views

grep IPs and port number into one line

Using grep and cut I have returned the IP and ports of the nmap scan result which looks like this: 192.168.1.221 80 443 192.168.1.223 25 Desired output: 192.168.1.221:80 192.168.1.221:443 192.168....
0
votes
0answers
18 views

filtering nmap script scan and outputting ip:port format

I'm grepping for anything that contains ssl-cert, this is so I can get the IP and ports for any certificates in use. Also I'm grepping 11 lines above the "ssl-cert" which gives me this output( the ...
1
vote
3answers
72 views

grep can't get the word I need, but Linux continues to do the next job. How do I stop it?

I have quite a few txt files. They contain the word 'Minimum' (it only shows once in each file), and I want to get the line that contains this word, and show the line in a new file. To do this, I use ...
1
vote
2answers
44 views

grep for single back slash

I am trying to grep for the mount output to see the options for the root directory. Why the following pattern (whitespace before and after a slash) is not working (with and without extended grep) /...
-1
votes
1answer
23 views

grep to a file from one server to another [duplicate]

I have a grep command like below zgrep '123_ERROR' xyz.gz I got lot of huge results where I cannot see top part. So what is best way to see entire result how to export results to a file zgrep '...
1
vote
2answers
42 views

Search specific numbers

im a list numbers in file and i would search 1 specific number in string Es. 1 54 67 78 32 11 4 67 89 90 13 67 87 32 21 My search is 1 With awk or grep commands out this numbers 1 11 13 ...
0
votes
2answers
66 views

grep with separate options for multiple patterns

I would like to apply the print only-matching option (-o) to one pattern specified by grep -e 'PATTERN' syntax, while another similarly specified pattern should display the whole line containing the ...
1
vote
2answers
54 views

How to search for a specific string in files from a specific date?

How can I search for a specific string in files from a specific date? For example, I have 3 files named 'a1' dated: 20 Feb, 'a2' dated 21 Feb, 'a3' dated 22 Feb. Now I want to search for a certain ...
0
votes
0answers
9 views

Trying to filter out maillog file with multiple “AND” matches [duplicate]

I'm trying to build a shell script. I've made the one line command using multiple sequental 'grep' just while investigating now, and I want to make a script to use next time, but it seems like a silly ...
0
votes
1answer
43 views

Bash regex and IFS split

I have the following problem: I want to extract text that is inside brackets from a string (with or without the brackets). My string looks like this: STR="[1] [2][345] [678 9] foo bar" I initially ...
-1
votes
2answers
39 views

Extract lines from a file with a value,whose parameter greater than 100, with grep and awk [closed]

I have a file, and I have to create a script with the following output file as per the specifications: The input file has first 28 lines of header, which have to be included in the output Some of the ...
0
votes
3answers
52 views

How to insert a line into a crontab AFTER a key word or string via script

I understand there is a lot of documentation on editing crontabs via script, and I can do this by adding an entry with the following command: line="* * * * * /my/folder/script.sh" ( crontab -l ; echo ...
0
votes
1answer
32 views

find out all the line numbers with binary non-text chars of a big log file

I have a big log file with non text chars. I used grep to search and I got this result: Binary file (standard input) matches I can use grep -a to skip these line with non text chars. Now, how can I ...
-1
votes
4answers
123 views

grep - ignore empty values [closed]

I am wondering is there an easy way to ignore search result output lets say like a $pacmd list-modules | grep -e 'name: <module-cli-protocol-unix>' -e 'argument: ' in this case the output is ...
2
votes
6answers
364 views

count how many times each number occurs

A file contains 5 columns with numbers Example: 12 34 67 88 10 4 90 12 10 7 33 12 5 76 34 I would like to print the same number and see how many times it goes out. Example: 3 : 12 2 : 34
0
votes
0answers
53 views

Using egrep in a find command to search for a variable and a constant

I'm working on a bash script to search a set of log files that record login attempts to the server and isolate if the most recent attempt resulted in an account lockout. First, I crafted a a variable ...
1
vote
1answer
87 views

Ansible task for searching words

With my ansible task I wanted to check if openjdk is installed on environment. - name: Check if java is installed on environment shell: rpm -qa | grep 'openjdk' register: result As result I ...
0
votes
2answers
31 views

Grep out a string but not for first row [duplicate]

I want to get a grep -v command that will remove the rows for that particular string found, without reading into the first row: orderID,change_timestamp,Condition,State OD10,2017-04-25 07:21:13.069,A,...
0
votes
0answers
26 views

How do I extract only certain parts of ffmpeg's standard output as it processes a file?

I want to enter a command that only shows these two lines of ffmpeg's output and I want to see it as it processes a file: from 'input_file.mkv': frame=172534 fps=4622 q=-1.0 Lsize= 8319963kB time=01:...
0
votes
2answers
36 views

how to extract strings

My data is like below sp|Q9H9K5|MER34_HUMAN(9-21) sp|Q9H9K5|MER34_HUMAN(493-507) sp|Q9H9K5|MER34_HUMAN(524-539) sp|P31689|DNJA1_HUMAN(22-33) sp|P31689|DNJA1_HUMAN(66-82) sp|P31689|DNJA1_HUMAN(93-104)...
1
vote
2answers
45 views

Select lines with two occurences of same pattern

I have several lines of output, some lines contain information on jobs waiting example I want to select lines that have more than one occurrence of the pattern jobs waiting: 0 example: abcdef rglk,...
1
vote
0answers
81 views

How to improve this 'sed' search & replace command?

How to search and replace recursively through multiple files in a directory, using essential tools installed in mostly any Debian/Ubuntu machine? There are multiple answers in Stack* where to find ...