Questions tagged [grep]

grep is a command-line text-search utility originally written for Unix. It uses regular expressions to match text, and is commonly used as a filter in pipelines. Use this tag only if your question relates to programming using grep or grep-based APIs. Questions relating to using or troubleshooting ...

1
vote
0answers
7 views

Using sed in Linux to extract lines from a log file

I have a log file which prints the following lines: 01:15:21.882 DEBUG [SampleProcess] Sample Message 01:15:21.882 DEBUG [SampleProcess1] Summary Report Sample Text1: 126 Sample Text2: 2330 Sample ...
-1
votes
0answers
7 views

how to insert a variable inside a grep -P expression (PCRE)? [duplicate]

When I do echo data/etc/config/file1.json | grep -P '(?<=data/etc/config/)\w.*', match is file1.json. Now, when I put the path inside a variable say, path=data/etc/config/ then this doesnt match ...
0
votes
1answer
10 views

Remove all path string from relative path

The following strings are in an html file that is a subset of the strings I have to work with: content/css/dashboard.css content/pages/icon-apache.png content/js/dashboard-commons.js sbadmin2-1.0.7/...
-1
votes
2answers
18 views

Print specific string in a line after matched word in bash

Situation There is a file called test that consists on the following text: this is the first line version=1.2.3.4 this is the third line How can i print via bash only: 1.2.3.4 Note: I want always ...
0
votes
0answers
10 views

Grep (BBEdit) is capturing too much - how to narrow a match

I am trying to match a string between start and end paragraph tags, so that I can insert a tag in front of "further text" and "even more text" in the example below. <P><HI>some text</...
1
vote
5answers
32 views

How to use grep with regex and patterns from a file together?

Suppose there is a file contains a lot of patterns .com .re .net ... And there is a file contains a lot of data www.recent www.remix3d.com www.verisign.net What I want the outcome is that www....
0
votes
3answers
30 views

Modify grep results to print a particular word from a match string

I have a grep ouput which looks as follows: Path to log files = /data/db2inst1/NODE0000/SQL00001/LOGSTREAM0000/ Database is in write suspend state = YES Path to log files = /data/db2inst1/NODE0001/...
0
votes
2answers
28 views

Awk the command output

This is the command what i run. ldap="$(ldapwhoami -x -H ldap://ABC.example.org -D "$user" -w "$pass")" This is the output result: u:ABC\1234567 May i know how to get the expected output ? like ...
0
votes
0answers
29 views

bash loop through masterfile to determine how many occurrences are in specific folder

I have a masterfile (master.txt) which contains multiple 4-7 character strings on each row (~38213 rows large). I also have a folder of data which contains multiple files (file1, file2, etc.) that ...
0
votes
1answer
22 views

Not able to access tables from a corrupted MySQL Dump file

grep -n "Table Structure" dumpfile.sql returns XXXXXX:-- Table structure for table `table_name_1` XXXXXX:-- Table structure for table `table_name_2` XXXXXX:-- Table structure for table `...
2
votes
1answer
24 views

Treat tmpfs as a device for grep

I have to test my program, that it completely removes files with their contents from disk. To test that I do the following: Create a file with some known string inside. My program deletes the file. I ...
0
votes
1answer
34 views

Unix - How to search for exact string in a file

I am trying to search for all files that contain exactly same id as listed in another file and put the file names in another file. I am using below command to find the files. grep -w -f SearchList....
0
votes
1answer
48 views

Grep output unreadable when redirect to file [on hold]

I have a script that receives an list of IDs as the 1st parameter and does a grep for each id against the file given at the second parameter: while IFS='' read -r line || [[ -n "$line" ]]; do ...
1
vote
5answers
48 views

pgrep -P, but for grandchildren not just children

I am using: pgrep -P $$ to get the child pids of $$. But I actually want a list of grandchildren and great grandchild too. How do I do this tho? With a regular programming language we would do that ...
0
votes
2answers
49 views

Extract portions of two lines into one

I would like a command line that would convert this input: capability: ESS Privacy ShortPreamble ShortSlotTime (0x0431) signal: -68.00 dBm last seen: 0 ms ago SSID: ENH202.FW ...
0
votes
1answer
38 views

Effective way of filtering a list

I am trying to extract subsets of a dictionary word list based on a certain criteria. The n selected words in each set/vector must have the same 1st, 3rd and 4th character as the ith More concretely,...
0
votes
2answers
20 views

UNIX, find string in all files in sub directory with line numbers and filenames

I'm trying to do a recursive text string search in UNIX and have the results show both the filename and line number on which the text appears within the file. Based on some other answers here I have ...
-1
votes
0answers
39 views

What is the equivalent grep command of CentOs in Ubuntu

I have following grep command number_of_inputs=$(($(grep -Pzo '^.inputs(.*?\\\n)*.*?$' output.blif | tr -d '\\' | wc -w) - 1)) that was written for CentOS to search for the number of inputs in the ...
2
votes
1answer
53 views

parsing lspci tree using regex

$ lspci -tv | grep -E 'Gigabit Network|Gigabit Ether| Ethernet' | grep -oP '(?<=^).*(?=Intel)' +-01.0-[01-04]----00.0-[02-04]--+-01.0-[03]--+-00.0 | ...
1
vote
1answer
47 views

Bash: echo showing blank value

I have two variables as follows SampleOutput=`some command giving output` Status=`echo "$SampleOutput" | grep -qs "Active"` echo $SampleOutput echo $Status Here $SampleOutput has value as ...
-2
votes
1answer
33 views

Need to grep only IP Address

nslookup google.com Server: xx.xx.xx.xx Address: xx.xx.xxx.xx#53 Non-authoritative answer: Name: google.com Address: 172.217.164.110 I just need the last IP Address with grep/awk ...
0
votes
0answers
20 views

Intersect large file: memory requirement issue on cluster

I would like to intersect a series of small files with a relatively large file. Following the many topics on stackoverflow and after some tests I choose to use this function which was the fastest on ...
-1
votes
1answer
33 views

Passing “>>” as an execv argument? [duplicate]

I am trying to pass some arguments into an execv call: char *const paramList[] = {"/bin/grep", "-rn", "comrade", "/home/sgspectra/Documents/testing_grep/", ...
1
vote
1answer
24 views

Subset df based on partially matched columns

I would like to subset my df based on the partial match between 2 columns. An example of my df: A B value 1 ABCDEFG CDEF 25 2 HIJKLMN CDEF 36 3 OPQRST CDEF 21 4 ABCDEFG KLMN ...
-2
votes
1answer
39 views

search based on contents of lines above and below a search term

So I have a log file that has text like this.. many variations of it though: m=audio 16468 RTP/AVP 0 8 9 18 120 102 104 103 101 a=rtpmap:0 pcmu/8000 a=rtpmap:8 pcma/8000 a=rtpmap:9 g722/8000 a=...
0
votes
2answers
61 views

search for text pattern in a directory using perl script

could anyone please share with me a snippet where i can do a grep search in perl file. Example, i need this grep: grep 1115852311 /opt/files/treated/postpaid/* to be done in perl script and print ...
1
vote
2answers
34 views

why grep does not return all pari of numbers?

Executing echo "123456" | grep -Eo "[[:digit:]]{1,2}" will return tree pairs, 12, 34, 56. Why it does not return 12, 23, 34, 45, 56?
0
votes
0answers
19 views

Why does my zsh-expansion & filter-combo of directories not work?

#!/usr/bin/zsh zparseopts -D -E -- p:=p -path+:=p r:=regex -regex:=regex gi:=gitignore -gitignore:=gitignore PATH=/my/path:/stuff GI=("${(@f)$(cat $gitignore[2] | sed '/^#/ d')}") R=("${${(@f)$(...
-2
votes
2answers
44 views

Using grep to find the correspondent error line item

I have the log file like this. I want to use grep command to find the reference to the error message which I want to get: "/home/ubuntu/CT/data/xml1/NCT0002xxxx/NCT00027222.xml". Would that be ...
-1
votes
1answer
54 views

Bash: Comparing ip addresses in two variables [duplicate]

I have two bash variables $checkVar = 10.10.10.111 10.10.10.112 10.10.10.117 $Server = 10.10.10.114 10.10.10.112 10.10.10.113 10.10.10.111 I want to make my test as PASS if ONLY first 2 values in $...
1
vote
2answers
34 views

Specific file name search UNIX [closed]

Hello i am new with UNIX and needed help with my search. I need to find a file that starts with 'f' than has unknown number of numbers then has 'gr' and ends with large letters also unknown number and ...
1
vote
1answer
37 views

How to extract each line which matches only first occurrence of particular character in that line?

I am working on a bash shell script. I have a variable which have a number of lines. Here: how can I extract each line which matches character 5 in column 5 ? declare -a T1 echo '$input' T=$(echo -e ...
-2
votes
1answer
20 views

How can I find all files in the current directory with matching text (excluding parent and recursive directories)?

I want to find: all the files in the current directory containing text search-term including hidden and non-hidden files without SomeDir is a directory messages
2
votes
4answers
83 views

Sed Every X lines, GREP between Y Lines

I have a file that basically contains arrangements of values as presented below (I have numbered the lines.) ! MATCH 1 ! 2 HIT 3 NUM 1 4 VAL A 82 5 LEU A 144 ...
1
vote
1answer
37 views

Using grep to find all php files containing variable of greater than specific length

I have some files with malicious code, I am struggling to find only those files having malicious code. for example the code in the file is like below: <?php $txppyfd = '...
1
vote
3answers
29 views

Count the number of occurrences of a string with a variable substring in a file in bash

I want to count the number of occurrences of a string Exiting with return code $var in a text file dump.out where 0<$var<29. i.e. I only want to consider the strings where $var is any value ...
0
votes
1answer
23 views

How to find a pattern with the specific file names in a nohup output?

I ran a for loop with several commands over different files in shell under nohup. I need to get the log values of one of the commands which gets printed on the terminal (in this case, in the nohup.out ...
-2
votes
2answers
59 views

awk bash recursive brackets id sed tr

A server provides a list of asset IDs separated by commas in square brackets after the date and colons : 20160420084726:- 20160420085418:[111783178, 111557953, 111646835, 111413356, 111412662, ...
1
vote
4answers
48 views

How to match nested text prefixed with spaces in sed or grep

I am trying to match nested text, including the line immediately prior to the nested text with sed or grep. An example of what I'm working with: pattern3 abcde fghij pattern3 pattern1 ...
0
votes
2answers
32 views

Extract average time using fping

I want to extract the avg time using fping. fping -q -b 12 -c 3 localhost 192.168.0.20 192.168.0.1 192.168.0.18 192.168.0.22 localhost : xmt/rcv/%loss = 3/3/0%, min/avg/max = 0.06/0.07/0.09 192....
1
vote
1answer
30 views

Two Onelinner For Cycle for list and grep Bash

I have a list of files with the following schema YYYYMMDD.tar.gz And I want to zcat to each one of them (I dont have zgrep) and then grep each one of them like this grep --color=always "STRING" | ...
1
vote
1answer
48 views

Change path using awk or sed

Hello i want to change symlink path to real path in txt file. First I find word "SF:" and change path. Now i use this script but it is slow and not effective. I think it can be changed by awk or sed ...
0
votes
0answers
37 views

Replace atomic numbers in a column with the corresponding atomic symbols in a file [closed]

Can anybody tell me how can I replace atomic numbers in the first column of a file by the corresponding atomic symbols in bash script? I have many file to be replaced this way. file:HCOOH 6 ...
-1
votes
4answers
41 views

Bash script that counts IDs in square brackets every ten minutes

Having this logfile 20180917084726:- 20180917085418:[111783178, 111557953, 111646835, 111413356, 111412662, 105618372, 111413557] 20180917115418:[111413432, 111633904, 111783198, 111792767, 111557948,...
0
votes
1answer
28 views

Grepping for 2 column, but there may be spaces in first column

I have a list... Group Chl# Code Name TMS ID Entitled SPP Basic 1 VOD Charter On Demand 32046 true Stream 2 KTVI KTVI 10750 true Stream 4 KMOV KMOV 10575 true Stream 5 KSDK KSDK 10685 true Stream 6 ...
0
votes
1answer
23 views

grepl across multiple columns - wildcard not working

I'm currently working with a dataset that has multiple similar columns: item1, item2, etc. through item8. Within a function I'm writing, I've created a specific search to use as the first argument in ...
0
votes
2answers
31 views

How can I replace lines from one file matched with lines from another file, based on matching pattern, with grep/sed/awk?

I have two files nmap.txt and hosts.txt. The first is, of course, the output from a nmap search, and it looks like this: ==================================== 192.168.2.1 (ComputerName1) ...
1
vote
1answer
41 views

Regex to extract a line in which the first word ends in a vowel

Actually I'm beginner in regex. I managed to do the following: egrep '[aeiou]\b' - the last character for each word is a vowel egrep '^[^ ]+' - first word of line But I have no idea how to write ...
0
votes
0answers
15 views

Why doesn't syslog output logs in file in /var folder ?

I have a simple question, I have a next c code: #define PINFO(fmt,arg...) syslog(LOG_INFO, "%s:%d(%s) " fmt,__FILE__,__LINE__,__FUNCTION__,## arg) void my_function() { PINFO("...
0
votes
0answers
10 views

grep pattern using cat separated by hyphens

So, I have a huge file which contains few line in format of a72nx2-sjjch-29nx92 b277x2-ncvwi-c9mcmwkk Note that, the digits separated by hyphen doesn't have have static length. So, in our example I ...