Questions tagged [grep]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
38 views

How to sort the content of text file .txt by files size

the file has been generated by ls -Raltr -block-size=M /* > /home/root/all_files.txt I have tried several commands with grep to no avail.
2
votes
4answers
75 views

More elegant approach to append text to a file only if the String doesn't exist?

I want to append NoDisplay=true to a .desktop file, but only if the entry doesn't exist. I do this the following way: grep -q 'NoDisplay=true' '/usr/share/applications/yelp.desktop' || bash -c 'echo "...
1
vote
2answers
44 views

How to search for strings that occur more than once in a line?

I know that I can use grep to search for a string. But what if I want the output to show only lines where the string I search for occurred more than once? I prefer grep.
0
votes
2answers
21 views

lookup a word in a file and verify the values for the last 3 occurances

I am performing a grep for word "percent" in log strings /var/lib/activemq/data/gc.log |grep percent | grep ten which gives me an output <mem type="tenure" free="2188996168" total="2617245696"...
47
votes
2answers
112k views

Reading grep patterns from a file

I have a couple of big text files and in the file UNIQS.txt I have a list of strings to grep from another file. The code I use is grep -f UNIQS.txt EEP_VSL.uniqs.sam > UNIQ_templates.sam which ...
-1
votes
4answers
49 views

Copying first line of text to another text file

Before: file1 123 456 file2 foo testing After: file1 123 456 file2 foo testing 123 Any help would be greatly appreciated.
2
votes
1answer
44 views

Piping grep output into grep inside a bash

I've got a text file, and I want to search for lines that have search_string but do not have exclude_string. In terminal, the following gives me the output I want: grep "search_string" | grep -v "\(...
4
votes
3answers
48 views

Grep doesn't work with both -v and -A/B

So I'm trying to use grep with both -v argument and -A argument. So my file has text like: This error -this -this -that [text I want] This error -asd -asfag -adsfhs [text I want] [text I want] This ...
1
vote
2answers
25 views

Grep data in specific pattern

MY File: "DocumentCreationDate="2019-07-15T23:56:31" SampleID="1" entClassID="65535" ClientID="0" CardID="11209797"" Want to grep Pattern : CardID="11209797" The number may be different between "...
0
votes
6answers
85 views

Simplest way to extract a portion of a string?

I've got a file (bigfile.txt), one of the columns looks like this NW_017095471.1 Gnomon mRNA 108321 109565 . + . ID=rna34;Parent=gene27;Dbxref=GeneID:108565285,Genbank:XM_017925071.1;...
0
votes
1answer
21 views

Grep “Pattern 2” only in files containing “Pattern 1”

I am trying to search for a "pattern 1" only in files that contain another string "pattern 2" E.g. A.txt Pattern 1 ... Pattern 2 B.txt Pattern Z ... Pattern 2 I intend to filter out files that ...
0
votes
1answer
49 views

bash + grep only the time stamp from output

we want to capture the time from the output and not the time from the command sshpass expected output Sun Jul 14 12:47:49 UTC 2019 Sun Jul 14 12:47:49 UTC 2019 Sun Jul 14 12:47:49 UTC 2019 but from ...
0
votes
1answer
981 views

Colorize line number in grep

Is there a way to colorize line numbers when using grep with the -n option? For example, echo "hello" | grep -n lo outputs 1:hello where lo is colorized in red (being the match). Can I configure ...
2
votes
0answers
26 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 "...
0
votes
2answers
30 views

How to count number frequency from specific column?

Below I have given my file (filename = 1.txt) structure. I want to count the number frequency from the first column and it should be started from line 3. Because the first line contains 411 and second ...
3
votes
2answers
37 views

Parallel Recursive Grep While Omitting String

Problem I cannot perform a recursive parallel zgrep while also omitting a string from the results. I am zgrepping through about 640GB of compressed firewall logs and almost %30 of the lines have the ...
6
votes
5answers
825 views

Extract an attribute value from XML

Using Bash, File: <?xml version="1.0" encoding="UTF-8"?> <blah> <blah1 path="er" name="andy" remote="origin" branch="master" tag="true" /> <blah1 path="er/er1" name="...
-1
votes
0answers
33 views

i am facing below error while moving file from path1 to path 2. but file were moved successfully

SCRIPT : FILES=/path1/NAME_????.csv ; for f in $FILES ; do if [ "$(grep -c "^" "$f")" -gt 1 ] ; then echo yes ; else chmod 777 "$f" ; mv /path1/NAME_????.csv /path2 ; fi ; done Error : ...
0
votes
2answers
1k views

Grep multiple files and output to multiple files in a single command

I will like to grep a particular pattern from 244 files and generate respective output files for each of them in a single command, how do I do that? My command for a single file is as follows: grep ...
0
votes
0answers
17 views

Search and display row of third word [duplicate]

How do I display rows that have value larger than 60 on the third word column? Text file 7/12/2019 23:59:45 39.00 7/12/2019 23:59:50 60.38 7/12/2019 23:59:55 0.53 7/12/2019 00:00:00 2.10 7/12/2019 ...
4
votes
8answers
19k views

Formatting the output of grep when matching on multiple files

When searching on multiple files, the output of grep looks something like this: {FILE}:{MATCH} This is a problem since if I double-click on the {FILE} portion, I will at least also select (and copy) ...
0
votes
2answers
30 views

sed deleting everything before ip address of host

I'm looking to delete every line before the IP address of the local host. I'm grepping the host's IP address successfully via: grep `hostname` /etc/hosts | awk '{print $1}' Now I'm looking how to ...
74
votes
9answers
156k views

How to grep lines which does not begin with “#” or “;”?

I want to grep smb.conf and see only lines which are not commented.
0
votes
1answer
69 views

How to detect and examine recent changes in a text file?

How to get last changes in text file on Linux? Example: text1 text2 text3 and then a programme adds another line to the text file: demo1 If the last change was the addition of demo1, print in ...
0
votes
1answer
27 views

How can I search terminal output?

Say I type git help to learn about the merge command. I don't want to read all the output just the lines that contain merge and their surrounding lines. I thought this would be a common question but ...
2
votes
2answers
1k views

Read from and append to file at the same time while preserving end-of-line

Conceptually I have an easy task... I have [loosely] structured data in a file: Testing: debug, default CXXFLAGS <100's of additional output lines> Testing: release, default CXXFLAGS <100's ...
0
votes
1answer
45 views

man <sth> | grep -A2 “SEE ALSO”

When I'm grepping a man page for the section titles written in capitals, it seems as if they are not there. It works with the same words in lowercase. For example, when I write man <xxx> | grep -...
7
votes
4answers
44k views

How to print only the first match with grep

I'm trying to grep username: users | grep "^\b\w*\b" -P How can I get it to only show the first match with grep?
0
votes
0answers
31 views

looking for help extracting the last dozen entries that match grep command

I have a log file that I pull data to a private web page to monitor my router. There are alot of entries. for each access control list. right now I have a simple php script. I only want the last 12 ...
0
votes
2answers
22 views

Remove trailing char if condition matches

Let's say I have a file with many URLs: http://foo.com/abc_(Programming_Language) http://example.com/test) I'd like to remove the trailing ) for each line in which there is no opening ( using sed ...
1
vote
4answers
626 views

How do I grep file paths out of a text file?

I have a file that has a list of paths like so: "1" "/user/bin/share" "2" "/home/user/.local" "3" "/root/" Is there a way to extract just the paths? I dont want the numbers or ...
9
votes
3answers
14k views

grep: input file 'X' is also the output

I use ubuntu 14.4, and attempt to redirect the output of grep command to a file, but I keep getting this error: grep: input file 'X' is also the output I've searched for this issue and just found ...
1
vote
4answers
98 views

How to convert Syslog Date-Time [UTC] to Epoch?

I am currently piecing together a tool to work with Syslogs generated in my network, one of the requirements is to convert the DateTime from the format in which it is in syslog (%b %d %Y %T) to epoch. ...
0
votes
0answers
38 views

GREP with multiple exact matches

I have an CSV file which holds information in below format - V1 V2 V3 1: ITC 02-01-12 96.4500 2: ITC 03-01-12 97.5833 3: ITC 04-01-12 97.0500 The Column 'V1' has many ...
-1
votes
0answers
48 views

Grep with '$' connundrum [duplicate]

System Ubuntu 18.04. Recently I discovered that on using grep with the '$' characters to search patterns at the end of a line in a text file, it doesn't always appear to work. I was searching my ...
0
votes
1answer
43 views

How do I match multiple number of digits using [:digit:] in grep?

I am for the first time using grep and after reading the manual I decide to use [:digit:] instead of \d or [0-9] for matching numbers. I found out that in grep, it is actually [[:digit:]] that matches ...
0
votes
2answers
26 views

Grep the URL's embedded in XML file

I'm trying to grep/sed from the following xml data: <record address="11.800.96.10" name="_ldap._tcp.gc._msdcs.example.com" port="3268" target="aws-sit2.example.com" type="SRV"/> I wanted to ...
0
votes
3answers
66 views

How to grep multi lines

I want to find all files, who contains two lines: abc and def. For example, xxx 111abc yyy 222def333 This file should be caught by grep because it contains abc and def. What should I do? I've tried ...
0
votes
1answer
18 views

How to get an output results as text to more than one location at once? [duplicate]

Is there a way that I can get a resulted output to multiple locations at the same time. ls -RsgorCh >> /Users/User1/Text1.txt will print the output as a text file in the given location. I want ...
1
vote
2answers
46 views

How to grep a data within a square brackets?

I have following type of data in my .log file: Cell[BoxData["0.8693473380926441`"] Cell[BoxData["100.40266203596555`"] Cell[BoxData["23.338724857049048`"] Cell[BoxData["0.25720321805387686`"] Cell[...
7
votes
8answers
26k views

How to grep rows that have certain value in a specific column?

I have a file as the following 200.000 1.353 0.086 200.250 1.417 0.000 200.500 1.359 0.091 200.750 1.423 0.000 201.000 1.365 0.093 201.250 1.427 0....
0
votes
2answers
34 views

Search a string on the specific columns using GREP/AWK/CUT

Kindly modify my script, because I want to search the word "dBm" in Column 1,3, and 4 of File.csv and return all unmatched lines/records 'cause "dBm" need to be deleted on the file. cat File.csv | ...
1
vote
1answer
24 views

Split a long grep pattern into multiple lines

To make my script a bit more readable I'm trying to split my long grep pattern. Is that possible? Example, in by bash script, instead of this long line smartctl -a /dev/sda | grep -Ei "...
2
votes
1answer
1k views

Filter screenlog with screen command

Pressing Ctrl+A, H, lets me log output of the screen command. However, the output file is too large. Is it possible to apply a grep-like filter so that I can control what gets logged? For example, I ...
2
votes
1answer
48 views

How do I avoid greping matching lines with -

I'm trying to grab only matching lines from a file using grep. The problem is that, when for example I use the following expression: grep -w AFFX-KIT-000088 textfile it will return: AFFX-KIT-000088-...
0
votes
0answers
12 views

Bash, autocompletion run commands with parameter

I have bash script kbase for 'cat' and 'grep -A10' from specified files for specific word with arguments. Main part of script. cat ~/bash/kb/*.kb | grep "## $1" | grep $2 | grep $3 One .kb file is ...
0
votes
2answers
28 views

How to grep a string with any two numbers that match or that have the first number one less than the second number?

I have a tab delimited file with four columns. I would like to grep for the lines that have a specific pattern in column 1, where it says apple M of N.  I only want to extract the lines that have the ...
0
votes
3answers
38 views

Linux grep - finding lines that contain same number

I am currently working with a file for atomic distances in a protein. Distances are either within the same residue or between different residues. I am wondering if there is a way to sort/find all of ...
0
votes
2answers
35 views

Bash - Find ID Pairs on One File Listed in Another File

I have a large file "F1" with listed id-pairs: id1 = digits, id2 = characters id1 id2 id1 id2 ... The goal is to extract the lines containing the id-pairs from a second file "F2", formatted as ...
0
votes
1answer
25 views

Simple Binary Replacement

I tried using bbe as below bbe -e 's/01110011/01111000/' test.txt All I'm trying to accomplish in this example is to read the file as if it's a binary file, and replacing the letter s with x. I'm ...