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 grep command-line options itself are off-topic.

Filter by
Sorted by
Tagged with
0 votes
1 answer
31 views

How can I get output in and out of grep from within a C program?

I wrote the following code. It spawns a grep, connects its input and output to some pipes, and sends in some text. Then it tries to read the output. When I run it, I see no output from grep. If I ...
Jack M's user avatar
  • 4,805
0 votes
0 answers
31 views

How to get specific word from string? [duplicate]

I want specific word from particular string. Prefix word will never change. I am trying to extract word from string. My logic is working for shell script. But when I'm trying to implement same logic ...
JK_IDR's user avatar
  • 1
-1 votes
1 answer
45 views

Locate text files with IP Address

I have used the ip address cmd. After pulling up my ip address and trying to use find or grep I get nothing when searching for text files that include the ip address. Following have been attempted as ...
Osgar's user avatar
  • 9
-2 votes
1 answer
52 views

only show lines above some pattern

git status On branch a5 Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in ...
Lewis Chan's user avatar
-1 votes
0 answers
66 views

Is there any way to have a script, to recognize any duplicate values in a file and remove them [closed]

I want a script, to detect duplicate values based on how many lines of same value is exist, then remove all lines with the value except the first line. I have such lines in a file: showlogin/ ...
Joker Security Lab's user avatar
0 votes
2 answers
26 views

jQuery - find object in array of objects based on partial match of one element

I have an array of objects, with one element being comma separated list of values. When a new object is created, I want to check if there is an object in the array that, among other things, might ...
NoBullMan's user avatar
  • 2,054
1 vote
2 answers
68 views

Grep match only the exact string in the line [closed]

I'm trying to grep for the word OK from the output of the below command valtool --validate <filename> which throws below outputs If success --> <filename>: layers signatures val OK &...
Chel MS's user avatar
  • 424
0 votes
1 answer
33 views

Using grep on macOS Monterey

I'm trying to use grep to locate a term in files on macOS Monterey, on Linux I use: grep -Rnw ./ -e "subject" --include=*.{c,cpp,js,xml} This doesn't work in a terminal on macOS Monterey. ...
SPlatten's user avatar
  • 5,362
-1 votes
0 answers
33 views

How to search range of values after a string using awk command? [duplicate]

I have a summary file with say: (A=8 B=19 C=25 D=100) almost 1000 lines. Sometimes A or B will not be there in the line. Using awk command I would like to find the lines where C values is between 1 ...
Harish Chuppala's user avatar
0 votes
2 answers
32 views

Why the file describer redirected changes after grep command? [closed]

$exec 3<input.txt $sleep 60 >&3 & [1] 32524 $ cd/proc/32534/fd $ ls -l lrwx------. 1 zhangchen zhangchen 64 Sep 24 18:29 0 -> /dev/pts/0 lr-x------. 1 zhangchen zhangchen 64 Sep 24 ...
chen zhang's user avatar
1 vote
0 answers
42 views

Grep with regualr expression not matching the whole string

This might be a dumb question, but ChatGPT does not do the job. In my understanding, [a-zA-Z\s]+ should greedily match a string with letters or spaces, as I tested with https://regexr.com/ and Python. ...
jeffma's user avatar
  • 21
-2 votes
0 answers
17 views

In Terminal , How would i search a .txt file to find how many times an occurence happened on each day if there were 3 seperate days?

There are 3 separate days of data in a .txt file. Each day shows multiple losses of monetary value, March 10, 12, 15... example: -$82,348. I need to count how many times a loss happened on each day. ...
Drew's user avatar
  • 1
1 vote
1 answer
60 views

Bash grep in github action always exits with status 1

In a github workflow I am trying to check if the version of my project is SemVer compliant by using grep to check if the version match the regexp for SemVer. I tried different ways to do it and never ...
Joe 010's user avatar
  • 35
-1 votes
2 answers
54 views

grep works with \s, but not with \s+

The following command works with \s echo "\"Using Android 10\"" | grep "\".*\sAndroid\s.*\"" and prints "Using Android 10" But if add a + as follows:...
Alexey Starinsky's user avatar
-1 votes
1 answer
48 views

How to extract a Jira Id from a GitHub squashed commit message using bash regex, sed, grep or groovy?

I would like to extract a Jira Id from a commit message string resulted from squash-merging a GitHub PR. If multiple Jira Ids are present, I would like to extract the first one. How to do it using ...
P. Luo's user avatar
  • 39
0 votes
1 answer
60 views

Shell or Bash script: Input a string line from a text file and search it recursively in a directory

I have a huge text file containing strings per line (properly edited with no empty lines or leading or trailing spaces) example input file WeatherNation.us AccuWeatherNOW.us FashionTVUHD.fr some upper ...
ls_milkyway's user avatar
2 votes
6 answers
120 views

How to create a list of all words in a bunch of files?

I'm dealing with a colleague who has made an enormous amount of copied/pasted spelling errors throughout an entire C# solution. Instead of using a spelling checker on every individual file, I would ...
Dominique's user avatar
  • 16.6k
-1 votes
0 answers
38 views

How to add the values of a grep command to a text file

I have a list of files that I need to update the username "jane" to another string. I've created the following bash script to find these files and append them to a new file test.txt. When I ...
Alexandra Araújo's user avatar
0 votes
6 answers
86 views

How can I extract the value of html TH tags that occur multiple times in a text file using a bash script?

I have a text file that contains html markup. I would like to extract the values in this section: <th scope="col" class="text-center">158</th> <th scope="col&...
Fadyboy's user avatar
  • 109
1 vote
1 answer
46 views

grep out 2 field only [closed]

input text: hello 34 others 28 I would like to run grep and get output the matched fields only: 34 28 I try below command but not as expected: echo "hello 34 others 28" |grep -Eo "([0-...
beetlej's user avatar
  • 1,853
-1 votes
5 answers
113 views

Bash Script To Get HTML Table Data

I have a web page that has a very simple HTML table. The HTML code of the webpage is as below. The HTML will always remain same, only the data values will change. <!DOCTYPE html> <html ...
Neha's user avatar
  • 9
0 votes
1 answer
43 views

grep with sed doing multiple replace

I am using the below command to replace all instance of schema_name.table_name to hello.schema_name.table_name in my file grep -rIEli '(\"|\s)schema_name\.table_name(\"|\s)' | xargs sed -E -...
Monisha P's user avatar
1 vote
3 answers
60 views

Grep and delete content from a file or update with new file

I have requirement to grep data with unique keyword and delete the upper line with below two lines. For example: Source file: { name: main phase: beta } { name: test phase: dev } I have used ...
user8845141's user avatar
1 vote
2 answers
55 views

How to input egrep result as a variable to awk

I have a dataset that looks like the below: col1,col2,col3,col4 read1,chr1,Unassigned_NoFeatures, read2,chr2,Assigned, read3,chr3,,Assigned What I want to do is to perform egrep on the "Assigned&...
Apex's user avatar
  • 1,055
-3 votes
1 answer
47 views

dollar sign ($) is not act as a placeholder for end-of-line linux [closed]

I have a text file(demo.txt) with the below content. mango apple orange banana papaya foo bar I have used a regex with grep to display only the string dog, the command shown below grep '^mango$' ...
sumith ps's user avatar
-1 votes
4 answers
88 views

Compare two csv and write updated rows to third csv in linux bash terminal [closed]

I am trying to compare two csv and generete only rows that has difference from linux bash terminal and output it to third csv in bash terminal grep -v -f csv1 csv2 > csv3 But i am not able to get ...
sysadmincrispy's user avatar
0 votes
2 answers
48 views

filter then merge output of 2 commands on a line level

Premis: i'm using run-ksql-test utility which has the output described in commands ouput section I have test files with the following output I just want to map the test status with the filename, and ...
deepakmeena's user avatar
0 votes
1 answer
45 views

Why is grep only partially working in an org-mode source block?

This is a follow up question about cleaning a SPARQL-dataset. The dataset is gained by this cell: #+name: raw-dataset #+BEGIN_SRC sparql :url https://query.wikidata.org/sparql :format text/csv :cache ...
lukascbossert's user avatar
0 votes
2 answers
61 views

Having Trouble with Bash RegEx and Grep – Need Assistance

Im trying to write a bash script that uses a RegEx pattern and takes this as input: # #------------------------------------------- spaceholder ------------------------------------------------------...
PopSmoke's user avatar
0 votes
0 answers
22 views

How to zgrep a specific key:value from .json.gz file

I have a bunch of logs in multiples .json.gz files. I can easily get a specific string with: zgrep "Search This String" * But now I need to find a specific value inside a key/attribute. I ...
PlayHardGoPro's user avatar
-2 votes
2 answers
48 views

probability of finding specific character from a random string present in multiple files [closed]

Let us consider the following files each contain unknown number of character. file_1.txt AACCGCCTTACG file_2.txt CAGGCGTTTAGGTCA file_3.txt GGACTGAACCTGTTAA I want to get the probability of finding ...
Akash Mondal's user avatar
-2 votes
2 answers
67 views

Analyze logs. How to filter by referce number [closed]

I have got following log.txt log 1111 xyzqwe log 1111 xyzrty aaa bbb ccc ttt log 2222 xyzuio log 1111 xyzopa iii uuu yyy log 1111 xyzsdf log 2222 xyzghj aaa ddd log 2222 xyzklz log 1111 xyzxcv ffff ...
Ferrum3000's user avatar
0 votes
4 answers
95 views

how to find two lines of strings in bash with awk or grep

This is a sample of data.txt: "line1":"text1", "line2":"text2", "line3":"text3", "line4":"text4", "line5":&...
Saeed's user avatar
  • 3,345
0 votes
1 answer
39 views

bash script to find failed tests count in dotnet test

I am trying to get the easiest way to find the count of failed tests using the dotnet test command's flavors. I am running my tests in gitlab and use XUnit. Basically, the test summary of the dotnet ...
DotNetDude's user avatar
0 votes
3 answers
70 views

Finding lines where the occurrence of word happens only after a specific searched word

Consider the below set of lines in a file: File1.csv Apple is red WHERE the column ALP_ACCT_PROD_ID, it can be plucked Apple is red ON ALP_ACCT_PROD_ID , WHERE it can be plucked I want to look after ...
Samrat Saha's user avatar
-2 votes
4 answers
69 views

Replace the last half in every line of a file with the last half of corresponding line in another file [closed]

I have two files A and B. Every line in both files is considered an item. The format of every item is fixed, consisting of a key and description, separated by a space. as shown in the example below. ...
echo's user avatar
  • 86
1 vote
5 answers
112 views

Select blocks of lines between $blockBEGIN and $blockEND containing specific pattern

I'm trying to select blocks containing a specific regexp pattern inspired from this solution : $ blockBEGIN='ID' $ blockEND='Sector Size' $ myPATTERN='Ready' $ cat pdisks-simplified-20230825.log | sed ...
SebMa's user avatar
  • 4,089
2 votes
2 answers
50 views

Conditional Editing of Large TSV in Linux

I have many large TSV files that have 6 unnamed columns and around 10 million rows. I need to apply a change on a row-by-row basis and save as a new TSV. I am working on Linux and have access to awk,...
JVGen's user avatar
  • 439
-1 votes
1 answer
43 views

How to solve issue Argument list too long in grep command? [closed]

How to solve issue Argument list too long in grep command? I need to execute grep command grep '^ORA' '/log/bssuser/CDR/Postpaid_CDR_Log/'*.log > output.txt I have error : -bash: /usr/bin/xargs: ...
Amany Abd Elmnem's user avatar
1 vote
1 answer
56 views

grep command for counting no of occurrences of a string in a file giving lesser number [duplicate]

I've a 6GB XML file that has only one line (verified with wc -l file.xml) This is the command I'm using : grep -o '<wd:Report_Entry>' file.xml | wc -l and it's outputting 446441. This is ...
duplex143's user avatar
  • 629
0 votes
1 answer
54 views

Grep XYZ and display line with only X + regex

I have this list of services list_services: user@10006 user@10007 user@10008 user@10009 user@1006 user@509 user@512 user@513 user@519 I wanted to know if it is possible to do : for service in $...
Frilowe's user avatar
-2 votes
4 answers
72 views

How to use Bash to grep, excluding some patterns, and including others?

In the file find.out I want to grep and find lines that have 'FinancePlus', 'Sungard' and 'Pentamation' and I want to exclude lines containing 'PROPRIETARY, 'CONFIDENTIAL', 'Public' I can get the part ...
user5586678's user avatar
0 votes
2 answers
61 views

How to split the file lines using particular delimiter and show in particular orientation format in shell script not using awk

Input File : input.txt <UndefineProperty name="admin.admin.adapters"/>--><!--<AddToProperty name="admin.admin.adapters" value="abc^abc.xz=abc"/>-->&...
Shr's user avatar
  • 19
-1 votes
1 answer
92 views

How to correctly exclude hidden files and directories in linux `grep` result?

I'm trying to exclude hidden files and directories in grep command. I found some answers here but they're not working: grep -r --color=always -n -H --exclude-dir='.*' -- 'something' The reason is ...
linrongbin's user avatar
  • 2,977
-1 votes
2 answers
79 views

How to map values from one file to another file and write it to another file using shell script

I have 2 text files. below text file is projectnameid.txt. first column is project name. second column in project id basket-items 9189 cloudfabric-notifications 10789 ...
MisterJay's user avatar
0 votes
0 answers
32 views

FilteringLogs using grep

HOW can i solve this problem using grep. The output of any command or stream can be piped to the grep command. Then, grep filters this output according to the match pattern specified and outputs only ...
Juan TV's user avatar
0 votes
3 answers
63 views

grep -v (invert match) matching word and line following match. -A -B not working

I would like to format output of the loop of command which checks correction of DNS settings of two domains across 12 dns servers for i in {1..12} ; do nslookup hostname1.fqdn ns$i.provider.fqdn; ...
AdamG's user avatar
  • 51
1 vote
2 answers
43 views

How to find if PHP file has constructor named the same as the class name?

I am checking PHP files to see if they have the constructor named the same as the class name. The name of the class is not known, until the word after 'class ' is captured. EG: 'class fooBar' would ...
Kevin Waterson's user avatar
0 votes
0 answers
28 views

Is there a way of formulating a GREP find and replace so that the first sub-expression is not changed but the second sub-expression is?

I want to apply a paragraph style to the first character after a page break (second sub-expression). But I don't want this style to be applied to the page break (first sub-expression). Is there any ...
Daniel James Smith's user avatar
1 vote
6 answers
142 views

sed/grep to extract word between 2 characters

My sentence is abcde^10=fgi^11=jkl^12=lmn The sequence can be jumbled also for eg. abcde^11=jkl^12=lmn^10=fgi The sequence can also be : 12=lmn^11=jkl^10=fgi^abcde I want to print lmn. I have ...
Achow's user avatar
  • 8,608

1
2 3 4 5
330