Questions tagged [grep]

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

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

Can you search for base64 with grep?

Is it possible to search for Base64 strings with grep? Say I have a list of text files and I want to find all the Base64 strings contained in them; is there any way to search for them? I mean I know ...
3
votes
1answer
160 views

Regular Expressions with `<` and `\?` strange matches

Assume, there is a simple test PHP script: <?php $a = ($argc == 2 ? $argv[1] : 10); for ($i = 0; $i < $a; $i++) { echo '.'; } echo PHP_EOL; Now, I do a grep or a conditional sed on the file: ...
-1
votes
2answers
35 views

To get the value of specific attribute value as True or False, having uneven columns

I am having one file with the below two lines in the file. I need to check if the value of xpoweredBy is true or false. Many thanks in advance. <Connector clientAuth="false" sslProtocol="TLS"...
-1
votes
2answers
47 views

Shell script- To fetch the content from the specific tag at all occurrence using shell scripting

I have an XML file on my server. In that file, I have many tags in which there is a tag for example, "container" tag. I need to fetch the content of all the container tags content separately. Many ...
0
votes
0answers
43 views

grep the particular line with regex dataset

I have a dataset which contains regex like HELLO_[0-9]* and I have to grep HELLO_2018 from the above dataset and extract the particular line as my dataset contains thousands of regex patterns with ...
-1
votes
1answer
58 views

find lines containing an exact string

I have a csv file which I am trying to extract only lines with "Ann_Pet.Fal". This is supposed to be very simple by typing grep -w "Ann_Pet.Fal" my.file. Unfortunately it does not work and I get any ...
1
vote
1answer
20 views

How can i use awk/Grep to search a specified column for a variable [duplicate]

I have data like the following: apple pear sugar pizza pizza chicken pasta turkey I want to grep for "pizza" but only grep the fourth column. I know i can use: awk '$4 == "pizza"' However i have ...
0
votes
0answers
38 views

Beautify the o/p of grep command

I am writing a bash script. It runs a couple of grep commands, and record the output of the grep command, in a text file. I am getting the output, but it is not formatted, so it is very difficult to ...
0
votes
1answer
27 views

How to cut specific lines from tab separated columns?

I have a file (.gff3) that has nine columns separated by tabs. ##gff-version 3 ##other information 0 . mRNA 1300 9000 . + . ID=mrna0001;Name=sonichedgehog 1 . exon 1300 ...
0
votes
1answer
39 views

Remote SSH Gnu/Linux server isn't recognizing my pipe

Basically I'm trying to run the following command: sshpass -p "xxx" ssh root@x.x.x.x "tail -f /tmp/messages | grep ptp4l" | cat -n > output.txt I'm trying to get tmp/messages to continually write ...
1
vote
2answers
53 views

Grep to get output after the first instance of a string

I'm currently using a CentOS image from Docker. What I want to do is get a certain value after grep encounters a certain string. In this case the string is 'inet'. What I have done so far: # ...
0
votes
1answer
37 views

I am creating a shell script by using grep to track a log

Instead of printing out this, ============ Normal grep location of the files ============ ems_inet1/SystemOut1.log ems_rpt1/SystemOut_19.09.09_23.00.00.log ems_rpt1/SystemOut_19.09.11_23.00.00.log ===...
0
votes
1answer
13 views

How to grep/sed a defind part of string that has spaces

I have a log that contains records like: LineFFF 1234567 0002 @2018-06-12T17:02:50 (len:0) 99 OK : jAFoSSYut2iJLmrk6fdQPL4OMRgd1Ybzb6U9MG1GeWKWqXlYPyfzyMVb9zn3 LineFFF 1234568 0044 @2018-06-12T17:...
2
votes
1answer
35 views

How do I use grep to search for the string “-1”

I'm using grep in bash to search for the string "-1" . I would usually search for "bar" like this ... glaucon@foo $ grep -irn "bar" ... which works fine but when I try to search for "-1" I get this ...
2
votes
3answers
58 views

How to combine these two grep statements

I need to select the lines that are not empty lines and do not start with //. I can perform two separate grep commands as follows: To extract the lines that are not empty line: grep -v -E '^$' test....
1
vote
4answers
66 views

grep file names from a text file and print the name of shell file calling that file into a text

I have some script name along with their path stored in a text file. The text files contains paths like /myhome/new1/myfiles/test2.sh /myhome/new3/myfiles/test1.sh /myhome/new2/myfiles/test4.sh /...
1
vote
1answer
37 views

Using grep to associate ttl in ping command with operating system

Currently I'm looking into scripting and was writing something that will ping devices on a network, state if its reachable, and then take the ttl data from the ping and stating it's operating system. ...
0
votes
1answer
40 views

How to count empty line using grep

I have a text file. Some lines contain text while others do not (just empty line without any spaces or characters: 123 // comment 45 As you can see, there is a line above //comment. If I want to ...
0
votes
0answers
45 views

replace text in html with links from xml files

I have a lots of html files where I need to replace multi text based on links inside xml files and seems the image ID is that will depend on it example htmls <div class="card" title=...
0
votes
4answers
120 views

grep finding ipv4 as words instead of lines

I have to find the ipv4 in a file.The problem is if there are other words on the same line as the IP the script wont print it.Here is my script: #!/bin/bash if [ -e ip.txt ] then grep -E '^(([0-...
3
votes
1answer
46 views

grep vs zgrep exit status differences with multiple files

Setup echo "abc" >/tmp/foo1 echo "def" >/tmp/foo2 cp /tmp/foo1 /tmp/gzfoo1 cp /tmp/foo2 /tmp/gzfoo2 gzip /tmp/gzfoo* grep exit status with multiple files and one match is 0 grep -q abc /tmp/...
-3
votes
3answers
47 views

Display all the lines in grepFile that do not start with a letter

I want a universal way of displaying all the lines in grepFile that do not start with a letter.
1
vote
1answer
37 views

Grep contents recursively, print only 1 directory level deep

I want to search within file contents, recursively on subdirectories, but I only care about whether the first level subdirectory contains any matches. That is, given: ParentDirectory ...
5
votes
3answers
206 views

pruning subdomains of other domains in a file using script (bash, awk or similar)

I have a huge size file (ten thousand entries) comprising of domains (in random order, but no duplicate domains and with an arbitrary number of subdomains), here is a little example: domain.com ...
7
votes
5answers
546 views

How to add some symbol (or just add newline) if the numbers in the text are not continuous

Ex: Input file A<0> A<1> A_D2<2> A_D2<3> A<4> A_D2<6> A<9> A_D2<10> A<13> Desired Output: A<0> A<1> A_D2<2> A_D2<3> A&...
1
vote
1answer
30 views

AWS s3 CLi grep command with special characters

I want to copy the whole log that are stored in the AWS S3 bucket if the following line is present: \"Key\" : 951332,\n I've tried escaping by trying this: aws s3 ls s3://bucket_name | grep "/\"Key/...
1
vote
1answer
51 views

how to make the inner loop faster?

I created my first shell script few days ago and while testing it during creation on few files, it worked flawlessly. However now in practice, I have over 12000 files to edit with it and it is going ...
-1
votes
0answers
40 views

Match regular expression: sequence of at most any 3 characters, in any order, repeated at least twice (grep or sed ?) [closed]

I want to match a sequence of 1, 2 or 3 characters, arrange in any order, repeated at least two times. Here is my test sequence: ...
3
votes
3answers
92 views

Exact number of same characters in word-grep

My task is to find lines with egrep in which first word contains exactly three same letters. I've tried to use backreferences but only found a way to build pattern which finds words builded from 3 or ...
0
votes
2answers
27 views

List top 5 processes for a specific user

I am trying to get the top five processes of a specific user in a bash: ps -Ao user,uid,comm,pid,pcpu,tty --sort=-pcpu | head -n 6 | grep <username> However, this selects the top 5 processes ...
0
votes
2answers
27 views

How can I best search for 2 instances of 2 consecutive words on a line with grep or other search utility

I have a log file that has 2 instances of 2 consecutive words on a line. Example: Process ID: 1034 Worker Process 4 I want to search for "Process ID" AND "Worker Process" on the same line. The ...
0
votes
2answers
48 views

Grepping exact difference

I have two text files like a 1111|100|11/11/1111|a 2222|200|11/11/1111|a 3333|300|11/11/1111|a 4444|400|11/11/1111|a b 1111|100|11/11/1111|a 1111|100|11/11/1111|a 2222|200|11/11/1111|a 3333|300|...
3
votes
3answers
72 views

How to grep to extract the previous n characters from a file

I'm trying to extract some data from a file using grep. The file is a DNA fasta file containing lines such as: ATCGTAGCTAGCATCGTATCGATGCTGCTATGCTAGATGCTAGT I need to find every TA and the 20 ...
1
vote
2answers
25 views

strange regex matching with grep/egrep

GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu) grep (GNU grep) 2.20 grep-2.20-3.el7.x86_64 Can someone explain this puzzle? I'm getting false matches with grep/egrep. echo "...
1
vote
1answer
56 views

How to find content in large sized files

I have a large-size text file.(about 2GB) I'll call you A.txt I want to know if the A.txt file contains the sentence I want(The size of the sentence is 1Byte~500MB) Also, if the sentence is ...
2
votes
3answers
91 views

How to append line which matches pattern to previous line

Ex: Input file ****************** .WER + aaa bbb ccc + ddd eee + fff ggg hhh ****************** .SDF + zzz xxx yyy + iii + kkk lll ****************** .XCV + uuu vvv ggg + hhh qqq + rrr ttt jjj ...
3
votes
3answers
73 views

Output only some part of a log line using grep

I have lines like these - /mnt/internal-app/logs/internal-app.log_2019-08-21.log.gz:2019-08-21 07:31:14,153 5458142 [XNIO-3 task-4] INFO c.c.p.i.m.ws.FileManger [FileName.java:1838] - UUIDs in this ...
2
votes
1answer
67 views

sed: -e expression #1, char 37: unterminated `s' command

Hi I'm trying to change the content of the multiple files in the folder. I encountered sed error while trying to iterate through array where I store names of the files I need to edit. I tried to use ...
0
votes
1answer
44 views

How to grep contents in HEX specifying the pattern in decimals?

I have a file with the following contents (as a text file in UTF-8) e04ba1af81d887979ddcee1dc23f2531 43f85926fdb6a668386ee354f8b836a1 b53614f5139c052ec08ea1ecd2532daf e9b3914d7b1e1bf8e6feab621330245b ...
8
votes
7answers
2k views

Get contents before a colon

I have a text file on Linux where the contents are like below: help.helloworld.com:latest.world.com dev.helloworld.com:latest.world.com I want to get the contents before the colon like below: help....
0
votes
0answers
29 views

print in awk works as a command, but not in .bashrc [duplicate]

I am running the command online | awk '{$2=$3=$4=$5=$6=$7=$8=$10=$11=$12=""; print $0}' and this command is working perfectly when I run it in the command line. However, when I add it to my .bashrc ...
0
votes
1answer
56 views

Parsing output from wget and grep using bash

I can get a url link and search for text that starts with file: but I'm having issues parsing it from there. Example: wget -qO- http://website.com/site/ | tr \" \\n | grep -w file:\* > output....
3
votes
1answer
57 views

grep -v -f alternative [duplicate]

I have two files. I want to exclude anything that is in file 2 from file 1. Example) File #1 - List of 500 domain names domain1 domain2 domain3 etc.. File #2 - Alexa's Top 1,000,000 domain names ...
1
vote
2answers
40 views

output mixed alphanumeric input with grep,pipe and cat

I have a mixed wordlist as an input: azert12345 a1z2e3r4t5 a1z2e3r455 The command line I have tried to execute: cat file.txt | grep -E "[[:digit:]]{5}" --color What do I want to accomplish: Print ...
0
votes
0answers
45 views

output only the mixed alphanumeric input with grep,pipe and cat [duplicate]

I have a mixed wordlist as an input azert12345 a1z2e3r4t5 a1z2e3r455 what i need to do is to print only the mixed alphanumeric words mad of 5 digits and 5 alphabets like (a1z2e3r4t5, azert12345) ...
0
votes
2answers
44 views

grep always exits with 0 exit status in if statement

I want to write a bash script that simulates Korn cd command: cd old new which substitutes old with new in PWD and then tries to cd to the new directory. here is the script: #!/usr/bin/env bash ...
1
vote
1answer
29 views

Mac OS xargs adds '?[m' at the end of line

I am trying to delete some local git branches with git branch -D $(git branch | grep 'RTL-1[1|2|3]' | xargs) However I am getting this kind of error error: branch 'RTL-1114_branch_name1?[m' not ...
0
votes
3answers
80 views

Extract key value pair data from avro file into a rows and column form using unix command/shell script

I have a file with following dataset. {"table":{"string":"ABC"} "TYPE":{"string":"U"} "TS":{"string":"2019-08-19 12:45:12.006362"} "C_TS":{"string":"2019-08-19 07:45:13.631000"} "dpt":{"...
0
votes
3answers
82 views

grep command in bash shell loop [duplicate]

I have a log file, name out.log. I need to search a list of string (filelist.txt) from this log file. I need each matching line from "out.log" for every file in filelist.txt. it can appear multiple ...
0
votes
1answer
58 views

Dealing with spaces in bash when piping the results from one command to another

I need to go recursively through several directories/files, in bash, replacing a certain string with another if it exists in a file. I had this solved in my script with the line: grep -rl "...