Questions tagged [grep]

For questions pertaining to grep, a command-line tool for searching text patterns in files. Use this tag for questions about grep itself or questions about issues arising from using the grep command-line tool.

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

return a list using grep (or alternative)

I am trying to return a list of "Name", "Exec" and "Icon" fields in /usr/share/applications/*.desktop I run: grep Icon= /usr/share/applications/*.desktop | cut -d '=' -f ...
user avatar
1 vote
1 answer
63 views

Extracting text with expressions from a text file using grep

I have the following 2 lines in my text file and wanted to calculate duration between those lines X & Y in minutes. line X: 18.05.2022 13:54:52 [ INFO]: Starting Component 'OWN_FUNDS_RULES' (5/15)...
user avatar
2 votes
2 answers
148 views

Looping through 'find' files and 'grep' to file character set result (standard input)

I'm using find to analyze a list of files. I want it to identify the files that are not ASCII files. So this is what I've tried on the command line: for me in `find 2022*`; do file -i $me | grep -L '...
user avatar
-1 votes
1 answer
30 views

-bash: syntax error near unexpected token `(' when using lookahead and lookback?

The use case is rather simple. I have a text file, say the following named eg.txt: 'simple_example': 345, 'to_demonstrate': 232, 'regex': 'is not easy to use' I am trying to capture the keys: grep -...
user avatar
  • 101
0 votes
0 answers
29 views

end anchor in regex with grep not working [duplicate]

I am attempting to list files that don't end in gz I have a minimal working example: ll chrX_PAR1.phased.vcf.gz | grep -v gz$ should show empty, but the file still shows, with or without quotes. I ...
user avatar
  • 107
0 votes
3 answers
46 views

How to remove line with specific string from file

Note the text file like this: /home/user1/dir1 /home/user1/dir2 /home/user1/ /home/user1/dir1/dir11 Goal is to remove line that has just "/home/user1/", nothing besides that, so end result ...
user avatar
-1 votes
1 answer
49 views

Find how many words in a file contain a number in them?

I am trying to find the total number of words in a specific file that contain a number. Not a specific number, I'm just looking for words that contain any number at all. I tried using the grep and ...
user avatar
  • 1
0 votes
1 answer
35 views

Do grep and cp treat "recursive" the same?

I'm having trouble with grep's manner of interpreting "recursive" searching compared to cp. Maybe it's just that I use them differently. In this, grep seems to interpret "recursive"...
user avatar
2 votes
2 answers
127 views

Command line - save sub-strings conditionally

Can a command line utility save sub-strings conditionally in different files? I have a file (file.txt) with several lines like the following. 1/1_ABCD4.txt:20020711 1/1_ABCD10.txt:20020731 2/2_ABCD2....
user avatar
0 votes
1 answer
37 views

Linux - count words with more than a certain length of characters

i want to know how to count the number of words in a .txt file that has more than 5 characters, using egrep and wc. Please, be clear as i'm new to linux.
user avatar
0 votes
1 answer
49 views

Return content between corresponding brackets

I have a file with all type of brackets {}[]()- nested, open and close appropriately. I would like to return the content within the matching square brackets after the string (text:). The content of ...
user avatar
  • 7
0 votes
3 answers
64 views

How to add column based in the second line match using SED or another command?

I have the following lines result from zcat command 1 - URL Template: https://www.test.com 2 - Response: <200 OK,{Server=[nginx], Date=[Wed, 11 May 2022 01:05:06 GMT], Content-Type=[text/html; ...
user avatar
1 vote
1 answer
30 views

Extract field and number of occurrences per line

I have this file: John Green', 'Age: 32', 'State: New York', 'Total cars: 2', 'Manufacter: General Motor', 'Model: Pontiac', 'Year: 2000', 'Manufacter: Ford Motor', 'Model: Endeavour', 'Year: 2010 ...
user avatar
0 votes
5 answers
89 views

How to ignore all text containing special character more than once?

Sample Input: apple_ig rabbit_cat_ig dog_ig bird_duck_ig orange_ig goat_ig Expected output: apple_ig dog_ig orange_ig goat_ig I need to ignore all data that contains underscore _ more than once in ...
user avatar
  • 1,001
0 votes
2 answers
18 views

How to grep for specific format

I have a .txt which has following strings. ANEW.0000+0530-0015+0530_NEW ANEW.0000+0530-0100+0530_NEW ANEW.0045+0530-0100+0530_NEW ANEW.0100+0530-0115+0530_NEW ANEW.0100+0530-0200+0530_NEW ANEW.0145+...
user avatar
  • 41
5 votes
3 answers
571 views

bash + how to compare arg to one of the disks in linux machine

I can capture the disk devices of my Linux machine with the following command: lsblk -lnb | numfmt --to=iec --field=4 | grep disk | awk '{print $1}' sda sdb sdc sdd In my bash script I used the line ...
user avatar
  • 10.9k
0 votes
1 answer
40 views

Count the number of words ends with specific character using Bash

Heys guys I wanted to count the number of words that end with 's' from this URL, https://matt.might.net/articles/what-cs-majors-should-know/ Here's what I did curl https://matt.might.net/articles/what-...
user avatar
-1 votes
2 answers
62 views

How can I add space after filename of grep output?

I am using grep to search matching patterns inside files, and copy its filename from the output. Since I do this operation a lot I may end up copying : as well. Hence is it possible to add two space ...
user avatar
  • 230
0 votes
2 answers
41 views

sed or other equivalent for grep with vfF

RHEL6.10 , gnu grep 2.2 grep -vfF stem.txt source.txt > filteredoutput.txt stem.txt has unique 13 digit numbers. source.txt is fixed length (400) data file where the 13 digit field value starts at ...
user avatar
  • 103
0 votes
1 answer
62 views

Grep inserting file names from working directory

I have script to do a few jobs: list config XMLs. list which of those XMLs have a match. show what that match is. JENKINS_HOME=/var/lib/jenkins _ALL_JOBS=$( find $JENKINS_HOME/jobs -name config.xml ...
user avatar
  • 1
1 vote
3 answers
83 views

How to substact or sum 12 depending on the last and following line using awk?

I have this data: ##sequence-region Q75T13 1 641 Q75T13,UniProtKB,Chain,1,641,.,.,.,ID Q75T13,UniProtKB,Topological domain,1,60,.,.,.,Note=Cytoplasmic Q75T13,UniProtKB,Transmembrane,61,85,.,.,.,Note=...
user avatar
0 votes
1 answer
49 views

I'm trying to understand how to shorten regex

I'm trying to list all directories that are 1GB or larger. I know I could use ncdu, but at the moment, I'm just trying to understand how to shorten regex... I found this command, du -h . | grep '[0-9\....
user avatar
-2 votes
2 answers
46 views

How to extract rows in a file based on common information in another file?

I have file look like: file1: 8189157 7423700 7227471 8189199 7533538 7574425 8189200 7533538 7574425 8189273 7241932 7538338 8191298 6353935 6770138 8191332 7427024 7756709 8192601 6353935 7378544 ...
user avatar
  • 1,263
-1 votes
0 answers
46 views

How can I tell grep to ignore color of input?

I commonly grep across syntax-highlighted text. As far as I can tell, grep searches the ASCII stream, which makes sense, but it means that the following: echo "$(tput setaf 1)foo$(tput setaf 2)...
user avatar
0 votes
1 answer
56 views

How to remember, which order grep and find takes the parameters?

Every time I use grep and find I'm stumbling through, which order I should type the commands: When I should write the path and when I should write the flags, if it needs double quotations or not, etc. ...
user avatar
  • 145
1 vote
1 answer
33 views

how to grep the results (plural) of another command

I have a command whose output I want filtered by the results (plural; multiple lines) of another command. So far I've been sending the results of the first command to a file and filtering the second ...
user avatar
  • 113
1 vote
1 answer
78 views

Matching lines in file, with 2 lists of strings in order

I am trying to match access-list lines in a file where certain environments (list A) are destination, and other environments (list B) are the source. And vice versa. This is on an Ubuntu server. ...
user avatar
0 votes
0 answers
24 views

pass output as grep pattern [duplicate]

I wish to pass each line of a file as a grep pattern to be searched in data.txt file. Thus, i need cat allsearchstrings.txt | grep <should be lines of allsearchstrings.txt> data.txt cat ...
user avatar
  • 297
-1 votes
3 answers
73 views

Need to format text file and update based of key value format

I have a file having the below values: cat data.txt server1: calv server2: anot log: /u/log/1 server3: calv server4: anot server5: secd server6: calv LIB_TRGT_calv,anot: /tmp/hello.txt LIB_TRGT_secd: /...
user avatar
  • 297
0 votes
1 answer
62 views

Grep find directory but root cant view it [closed]

Why grep can find a folder, but root cant nor view file in this folder nor cd this folder? this is terminal output using grep -rh "addons27" / I trying to find releases directory in OpenErp ...
user avatar
0 votes
2 answers
30 views

grep results with spaces and special chars

I am trying to grab results from lshw and add them to a a bash array so I can create a new string. I am using lshw -class disk |egrep -A 7 .'-d' |grep 'product' |cut -b 17- the output looks like this ...
user avatar
  • 1
1 vote
1 answer
17 views

Pipefail prevents command substituation from evaluating pgrep?

My goal is to run a pgrep lftp -c command inside a shell script to check if lftp is already running. But the following script never goes beyond "test" output. Only if I remove the pipefail ...
user avatar
0 votes
3 answers
83 views

Count the number of occurrences of a word in a text file Linux

I have a text file and I want to count the number of occurrences the word Orange or orange appears in the text file. orange or Orange should not be part of a word(i.e. "oranges","...
user avatar
  • 53
0 votes
1 answer
19 views

Deleting Files in a Directory that contain a single quote (') character

I Have files as such: "contrail's", hello , "larch's"...etc How could I delete files that contain a single quote (') character(ex: "kibosh's" ). I was thinking in using ...
user avatar
  • 53
0 votes
0 answers
17 views

Deleting A List Of Files Using Grep [duplicate]

I want to delete files in a given directory (/home/cs12/derf/files) which only contain the single word "Delete" in its file contents. Any file that does not have the expected content should ...
user avatar
  • 53
3 votes
2 answers
236 views

Deleting Files From A Directory Containing A Certain pattern In The File

Let's say I have a directory called "/home/ben/files" with 100 randomly named text files. Out of the 100 text files some just contain the word "DELETEME" inside the text files. e.g....
user avatar
  • 53
0 votes
3 answers
108 views

Filter without relying to an html entity one line huge string based on a start end match and keep text in between the pattern no matter the length

I have a one line file like this Pastebin but way longer. My goal is to filter only parts of the string that example1: start with <a end with </a> example2: start with PZ end with s16 and so ...
user avatar
  • 121
1 vote
1 answer
26 views

Why does grep generate "xterm-256color"

I'm working with Ubuntu 16.04.4 LTS. I used Mobaxterm to login remotely. When I execute grep, something weird happened... me@mymachine:/data/myserver/log/server$ grep -rnH 23423 ./*log ... # outputs ...
user avatar
  • 2,809
0 votes
1 answer
22 views

How to verify that source code does / does not provide driver for Apple USB modem?

Source Code: https://unix.stackexchange.com/a/698474/182280 The goal is to verify that the source code has the driver to support an Apple USB Faxmodem MA034Z/A. What are the keywords or phrases to ...
user avatar
  • 1,104
0 votes
1 answer
41 views

String searching with grep [duplicate]

I'm just searching in emacs some strings with following pattern: ^*DEFUN*event*$ So i've used grep: grep -nR "^*DEFUN*event*$" * but got no match, instead there's a lot of them for example:...
user avatar
-3 votes
4 answers
84 views

Grep for lines of text that have one occurrence of exclamation mark

Let's say I have a file with this content: some:text:!someothertext another:text:!!anothertext I want to grep only for the lines of text that have only one occurrence of '!' This is what I have and ...
user avatar
  • 361
6 votes
4 answers
531 views

grep with Bash-Globbing-like search pattern

I would like to use a very simple pattern matching with a grep-like command. Background is grepping a list of names of VMs, for example a commands that lists just the names of Virtual Machines, where ...
user avatar
  • 111
0 votes
1 answer
61 views

How do you use grep with man command? [closed]

I saw a guy how used this command man ssh grep -e "version number" and then got the option printed out for him. But when I do the same command, I get the same result as man ssh. So can the ...
user avatar
4 votes
3 answers
1k views

How do I use Unix commands to print lines that contain Chinese characters OR lines that contain ###?

I have a text file and I want to use Unix commands (I don't care which) to print lines that contain a Chinese character OR contain the string ###. This answer has a grep command which prints out the ...
user avatar
0 votes
1 answer
38 views

How do I extract the content of quoted strings of a specific property path from an output?

I have an output from a web server response in JSON which looks like this: {"status":"OK","result":{"string":{"variable":0},"string2":[{&...
user avatar
  • 3
0 votes
1 answer
61 views

Is "egrep" part of the POSIX standard

The egrep command has been deprecated in favour of grep -E. The POSIX definition for grep includes the following note, This grep has been enhanced in an upwards-compatible way to provide the exact ...
user avatar
  • 88.9k
2 votes
2 answers
69 views

Bash Script Put Text at the Beginning of all Files if Conditions are Met

I'm trying to write a bash script to put text at the beginning of all files in all subdirectories only if: The file does not contain that text The file contains the company's name, the word River, or ...
user avatar
-1 votes
2 answers
55 views

Grep for words not lines

I need to search a text file for a word count. The file contains lines of sentences and I only care about the number of times a word shows up not the number of lines. How do I tell grep to search for ...
user avatar
3 votes
1 answer
126 views

Trying to put output of grep command into a bash array

If I run the following grep command I get the output I am expecting: $ grep -o -E '/ |:|\\|<|>|\*|\?|\"| $' <<< '/home/ttwaro/temp/Test/This is a Test: Testing Number 1?/This is ...
user avatar
  • 31
0 votes
5 answers
214 views

Remove the matching pattern from grep's output?

With bash, I'm running this: declare -p | grep 'declare -- ' That prints whole lines. I want to print those same lines, but I wanted to exclude the match itself. i.e., Can I do ... | grep pattern | ...
user avatar

1
2 3 4 5
94