Questions tagged [grep]

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

Filter by
Sorted by
Tagged with
0
votes
3answers
868 views

Grep latest file for string and alert / email if found

I want to grep this string 'FCE-Error' from a folder than contains loads of text based files The folder looks like this -rw-r--r-- 1 root root 0 May 22 10:30 T201805220930.CIR -rw-r--r-- 1 ...
0
votes
3answers
53 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
72 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
50 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 "...
1
vote
3answers
3k views

Check if the particular string is present in a output of shell script using shell command

I have a shell script (test1.sh) which returns the following output Employee ID emp Type return type Admin User us321000034006755 ITdept access Itadminuser I wanted to ...
-4
votes
0answers
27 views

grep command if anyone can help me to get respond to the question below [on hold]

Question 1: n the command grep 'your-answer-here' myFile.txt what would you write between the quotes to select all lines of myFile.txt that contain an uppercase "A", "B", or "C"? Question 2: In ...
-7
votes
0answers
49 views

Real Challenge on this one… I think [closed]

I need to know how to read a certain position in a line that only begins with 8200, then take positions 5-10 and subtract 1 from it, then put that value into position 5-10 to replace it. Example: ...
2
votes
1answer
100 views

Sqlite: replace a string modelID1/modelID2/modelID3 with name1/name2/name3/

My goal is to read the macOS Photos.app database to find out the paths of the included photos. The album and the parent folder whose name is in the RKFolder table can be determined for each photo. ...
0
votes
1answer
38 views

Replace part of a line by other part of the same line

I do have a file like this: <receiver name="anything" type="com.mycompany.plugin.Timer"> <property name="interval">5000</property> <handler name="ReplaceThis" type="com....
-2
votes
1answer
40 views

Need to fetch only the required part

We have a string as below: **XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" FCP_USERID=5667 FCP_USERNAME="SRI" FCP_PRINTER="noprint" FCP_SAVE_OUT=Y FCP_NUM_COPIES=1 "...
1
vote
2answers
40 views

Extract file with two matched strings at the same time

I have a list of species and a master record from database. I wanted to search for the match of species in the third column of master record file and print out the whole line. species_list ...
-3
votes
1answer
32 views

How do I count all the lines of code in all headers and source files in a folder? *.cpp *.h [duplicate]

Say I have a project folder containing a number of header and source files for c++; How would I count the total number of lines of all of these?
0
votes
0answers
25 views

Trouble looping if grep statement [closed]

So I would like a command to be executed based on whether or not grep found the exact phrase in each of the specified .out files. Currently the command looks like this: for i in R[R,S]*.out if ! ...
1
vote
1answer
27 views

How to parse strings from a file in multiple other files?

I am trying to grep a list of strings listed in 7253.txt which looks like this: rs11078372 rs1124961 rs11651880 rs11659047 rs1736209 using: grep -o -f 7253.txt *.logistic > result.txt from ...
0
votes
1answer
20 views

Bash filter text content with strings from another text [duplicate]

Untill now I used everytime to filter, grep command [root@host tests]# cat e 1 2 3 4 5 [root@host tests]# cat e | grep -Ev '2|3' > filtered.txt [root@host tests]# cat filtered.txt 1 4 5 [root@...
9
votes
1answer
871 views

Trying to write a shell script that keeps testing a server remotely, but it keeps falling in else statement when I logout

Trying here to write a shell script that keeps testing my server and email me when it becomes down. The problem is that when I logout from ssh connection, despite running it with & at the end of ...
5
votes
2answers
3k views

grep string where next line does not contain string

I want to search all files inside a directory and its subdirectories for lines containing a certain string, but I want to exclude those results that contain a different certain string in the line ...
-1
votes
1answer
48 views

grep to $URL then sed $URL

I have in 1.txt: https://www.google.se/ https://www.bing.com/ URL=$(grep ".*" ./1.txt) | sed "s/$/\">${URL}/" ./1.txt > ./2.txt I get in 2.txt: https://www.google.se/"> https://www.bing....
55
votes
3answers
46k views

grep inside less?

I'm currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event ...
0
votes
1answer
113 views

How to find definitions in standard librarys using the gcc preprocessor?

I have found in my project a type definition, which is definitely from a standard library. Lets say the definition is called uint64_t . I would like to know, what definition is exactly behind that ...
0
votes
2answers
991 views

using grep exact match, using a list file to look into another file

I have two files - one with some IDs (text file) and other with IDs and descriptions (tab file). File1: 31120 211890 542312 File2: chr10 31120 A T Descriptions Chr11 131120 A T Descriptions ...
2
votes
3answers
57 views

Grep only a given number of lines after match

I need to create a new file from a grep match but with maximum number of lines. Something equivalent to this but one-liner $ cat my_log_file.log | grep -v auto > filtered.log $ head -n 1000 ...
23
votes
4answers
53k views

How to use grep when file does not contain the string

In my bash script I'm trying to print a line if a certain string does not exist in a file. if grep -q "$user2" /etc/passwd; then echo "User does exist!!" This is how I wrote it if I wanted the ...
6
votes
3answers
352 views

Find a text string in a file and output only the rest of the text that follows it?

I am finding a lot of posts on this forum that have to do with finding various values in a text file and outputting text surrounding it. However, I don't seem to find any "stream oriented". I want ...
0
votes
2answers
42 views

Character class regex confusion

I'm trying to abbreviate a regex in a grep. I need to match exactly six spaces followed by an alpha character. This works: grep "^\s\s\s\s\s\s[[:alpha:]]" <filename> This does not: grep "^[[:...
0
votes
1answer
29 views

Solaris - Get directory names that starts with a pattern

I'm working on Sun Solaris 10 OS, which is grep -o is not allowed with modern systems. I have the below list of directory I'm trying to fetch any directory starts with DATA[0-9] only DATA34016 ...
-5
votes
2answers
58 views

Can someone tell me what this command does?

I have encountered the following command in an internet tutorial. I couldn't understand how it works. git log | grep commit > ~/filename.txt Someone please explain me how it works.
2
votes
3answers
69 views

How to grep data of a new line when capturing a keyword?

I have a file which contains below sample line having a common keyword P00001121 in each line. [H00,P00001121] CHANNEL__OPEN:TCP_ADDRESS='10.32.130.202' TCP_PORT='80'" [H00,P00001121] COMMS_QUEUING:...
14
votes
7answers
5k views

How to find files with 100% NUL characters in their contents?

What is the Linux command-line command that can identify such files? AFAIK the find command (or grep) can only match a specific string inside the text file. But I want to match whole contents, i.e. ...
1
vote
1answer
2k views

Need to find a response time which takes from 1-3 seconds in Apache logs

I need to find the API response time from an Apache log file. It's like a response time which is takes between 1 to 2 secound or 2 to 3 second. $6 is response time and values comes in microseconds. I ...
2
votes
3answers
224 views

How to get single character after space?

How can I get below output? I want the first field as it is and a single character after space. echo "Hello world" Hellow If it also has a 3rd field than the beginning character of the 3rd field ...
12
votes
3answers
3k views

Can I shorten this filter, that finds disk sizes over 100G?

My goal is to get the disks greater than 100G from lsblk. I have it working, but it's awkward. I'm pretty sure it can be shortened. Either by using something totally different than lsblk, or maybe I ...
2
votes
1answer
62 views

Struggling with output of grep into an array

Please note I'm not a developer but I have requirements where I'm trying to search an SVN repository for files containing certain table names. I have built this script on the basis of many things I ...
2
votes
1answer
46 views

grep Commands in Unix

Is there any difference between grep “^[^a-z]” foo and grep –v “^[a-z]” foo? It displays the same output whereas the first command displays some highlighted characters. Is that the only difference?
0
votes
2answers
30 views

Extract a part of line from logs

I have the following lines in a log file: <ROW USER_GID="TEST 1" FLOW="Norm" SEQUENCE="9"/> <ROW USER_GID="TEST 2" FLOW="Norm" SEQUENCE="2"/> <ROW USER_GID="TEST 3" FLOW="Norm" ...
1
vote
1answer
885 views

Grep -v filter not working

I want to filter grep results by using grep -v option. But the output does not differ when using a particular pattern. contents of log.log: ERROR error EXCEPTION exception <STATUS>ERROR</...
11
votes
1answer
14k views

Return owner of process given PID

I'm trying to grab the owner of a process from a list, I have the command pidof nmap to get the then ps -u <PID> | grep USER that I'm currently playing around with, but when I run it, it ends ...
2
votes
1answer
715 views

Ideas for parsing netstat results for active connections

I have several remote devices that create reverse ssh connections back to my server, so that I ssh to them and manage them remotely. They connect back to me via a custom port. When I do a netstat -...
1
vote
2answers
34 views

How to grep multiple lines?

Grep understands this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "clipper-coin" But not this : curl https://api.coinmarketcap.com/v1/ticker/ | grep "{*clipper-coin*}" The output I ...
0
votes
0answers
48 views

How does grep determine if a file is binary or text, and what are the differences between `--binary-files=text` and `--binary-files=binary`? [duplicate]

In order to configure my grep options correctly, I need to understand how grep determines if a file is binary or text - and how grep behaves accordingly. From the grep man page, the following ...
2
votes
1answer
53 views

Is it possible to grep from a stream that has no new line?

When running this code: while true; do printf "Match Unmatch\n"; sleep 1s; done | grep -o "Match" in a terminal, grep finds the word Match. I get the output: Match Match Match ... However, when I ...
1
vote
1answer
39 views

Find a specific record from an XML file [closed]

I have an XML with one record each in same xml tags; sample given as below. I need to get the specific record displayed by giving the search pattern as '4017|95592'. Output should be: 4017|95592|S|Y|...
0
votes
1answer
39 views

how to find a text in a file in UNIX without using grep command

Is there any other way to find a text in a way without grep command from multiple files. This was asked in one of my interview but I could find a possible solution for this question.
0
votes
1answer
83 views

Add folder name ($date) to top of log then cut line 21 from same log and add as a value in running script

I am trying to create a script and I am stuck on the final part I want to add. The script syncs some paths on my server to my google drive. If there are any deleted or modified files on my server it ...
0
votes
3answers
50 views

sed/awk/grep parse email on filtered txt files

I have several txt files and would like to extract email from that file if file contains text "Provider" inside. Text files are not equally formatted. "provider" could be anywhere in text. Here is ...
-2
votes
1answer
47 views

How to grep single quotes grep “ ' ”? [closed]

I'm smashing myself trying to grep single quotes, not a word within single quotes 'word', but " ' ' " cat file; . $servers->setValue(‘server’,’base’,array(‘dc=aulendil,dc=com’)) . and I want ...
4
votes
1answer
57 views

Difference in output of GNU and BSD zgrep

I am using zgrep to search a pattern and print N lines after the matched line from multiple .gz files. In BSD zgrep I see a separator -- after each file: zgrep (BSD grep) 2.5.1-FreeBSD $ zgrep "...
4
votes
3answers
376 views

How to extract only values greater than a threshold

I am new to bash scripting. Could someone help me with the following? I have a log file with output as shown below. I'm trying to grep for lines of an output with logDurationMillis>=950ms logAlias:...
2
votes
3answers
1k views

Grep for multiple strings, show number of lines after one of the strings (but not the other)

I would like to search a file for multiple strings and for one particular string, show the 5 lines following it as well. cat file | grep -e 'string1' -e 'string2' works of course, but I would like ...
1
vote
2answers
57 views

get count with grep

im working on sun10 Solaris os,i have a process that returns table as by using this command dmh -q 12 the below: *PROFILE PRIORITY COMM_TYPE QID # OF MSGS ATTRIBUTES/VALUES* 13 ...