Skip to main content

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
1 vote
2 answers
55 views

Need to make multiple multiline replacements in file

I have a file with multiple "paragraphs" like this: <type>TRANS</type> <attributes/> <specification_method>rep_name</specification_method> <trans_object_id/&...
Todd Porter's user avatar
2 votes
1 answer
61 views

Grep return No such File, after comand substituion

I'm trying to use grep in a Bash script and assign the result to a variable: RESUlT=$(grep -R -I --exclude-dir=addons "^[^#]*print(" ) But it returns bash: Map/Places/place.gd:: No such ...
T.S's user avatar
  • 23
2 votes
2 answers
85 views

sed in conjuction with xargs and grep not working

I'm trying to change a string in multiple text files (configurations migrated to other user). I used this command: grep -iIlr "/home/user/.local" | xargs sed -i 's/\/home\/user\/\.local/~\/\....
Krackout's user avatar
  • 2,742
-2 votes
1 answer
76 views

Is it possible to read user input with no extra variables?

I want to grep an IP address inside Nginx configuration files. I want to input the IP address with the read command, but I don't want to store input in an additional variable. So I want something like:...
palmasd1's user avatar
  • 125
-1 votes
2 answers
96 views

How to diff two files in bash efficiently?

I have two files containing the similar pattern: cmd1 [cmd2 {xx/xx[7] x/x[0] ...}] cmd3 [cmd4 {xx/x[12] ...}] cmd5 [cmd6 {x/x[1] xx ...}] I don't need to consider all the cmds in two files. Only need ...
Alan Gatsby's user avatar
-2 votes
3 answers
117 views

Bash script: echo output of variable and write to file

I am trying to write a script which will check to see if the contents of a file match a certain value and if so, overwrite it with contents of another file. Example: file1 = A, B, C, D 1, 2, 3, 4 ...
Joseph Woodward's user avatar
-1 votes
2 answers
76 views

I need to filter out `grep`'s output to find a device's serial number, in order to store it into a variable

I'm working on a section of a script that will find the serial number of a Mac, store it into a variable and rename the device according to the naming standards of my workplace. So far, I have the ...
TheBigDog's user avatar
-1 votes
1 answer
53 views

awk inside function causing errors

I'm trying to add the following to my .bashrc: cpu_info() { top -b -n1 | grep Cpu(s) | awk '{print $2 + $4}' } but bash is telling me: bash: .bashrc: line 131: syntax error near unexpected token `...
Mathew's user avatar
  • 243
0 votes
1 answer
73 views

How to use grep string that has double quotes in it

So I'm running a simple alias called vpn which runs a command and has an output, which I put into a .txt file. If interested to what exactly then here is the alias alias vpn="docker exec -it ...
Arelius's user avatar
  • 73
0 votes
1 answer
48 views

grep command regexp behaviour, is there a workaround? [duplicate]

I wanted to extract from a text all capitalized words that do not start a sentence or follow a period. I managed to do it with a combination of sed and grep but got stuck for a while with grep's ...
Pikko's user avatar
  • 16
1 vote
3 answers
57 views

using grep (or something similar) to find when rows are missing

I'm trying to find when certain rows are missing in a file. See below. In each record, there is an ItemNumber, MessageNumber, NewItemNumber, and ConfirmedQty field. Is there a way to find ItemNumber ...
Dan's user avatar
  • 11
-1 votes
1 answer
44 views

zgrep command not working correctly on command substitution [duplicate]

I am preparing a script that will try to detect two texts on the same line.  This pattern is present in my application log files, which then further used to identify which file contains the pattern. ...
Piyush Nikhade's user avatar
2 votes
3 answers
280 views

How can I use find paired with grep to delete files

I am attempting to write a script to delete files from a directory. find /home/docs/* -name "*.log" -type f -print -exec rm -f {} \; The above works however I need to use grep to target ...
newdeveloper's user avatar
-1 votes
2 answers
97 views

Recursively search for txt files that has all the search strings

I want to find all the files that has the words “Who”, “What”, “Why”, “How”, “When”. All of the words, in any order. Case Insensitive I tried: grep -rl --include='*.adoc' "Who" . | xargs ...
Ahmad Ismail's user avatar
  • 2,728
0 votes
3 answers
89 views

regex in grep vs sed

I am trying to find and replace all lines in a text file that start with a single space and then any characters. Finally got the regex to work on grep grep -E '^ .*$*' Contacts.vcf >> t.txt Then ...
atclaus's user avatar
  • 101
1 vote
1 answer
86 views

What does "/$" mean to "grep"?

I'm using these two codes below. ls -lap . | grep -v "/$" ls -lap . | grep -v "/" These two give me different outputs in some cases. What does $ mean in that context?
shersher's user avatar
0 votes
0 answers
70 views

Text processing grep and awk together on live script not working

I am using ssh to login to a remote server (Ubuntu), and then issue a command which outputs text/value each sec (live script). In the live output, I want to filter out the lines containing '...
SAM's user avatar
  • 1
8 votes
5 answers
2k views

How to execute a command on all files whose names match a pattern and whose contents match a pattern?

Say I want execute cmd on all *.cpp and *.hpp files that contain the word FOO. As far as just finding those files goes, I know I can do, find /path/to/dir -name '*.[hc]pp' -exec grep -l 'FOO' {} + ...
Enlico's user avatar
  • 1,677
0 votes
2 answers
82 views

Find out if user name and database are matching | grep

I found that grep -w 'desired_string' should deliver just lines exactly desired_string, but not desired_string-22 or any variant. What I need is a check if a certain Postgres database is owned by a ...
herrdeh's user avatar
  • 11
1 vote
3 answers
74 views

How can I view only non-storage devices using lsusb, lsblk, or similar?

I'd like to see a list of connected USB Devices (eg. Usb Mouse, USB Keyboard) without having to go through a list of devices that includes internal and external storage devices (eg. internal HDD, USB ...
Lee's user avatar
  • 97
-3 votes
4 answers
109 views

How to catch all lines of a repeating pattern and do some actions with the subresults

I am looking for a possibility to catch in a repeating text pattern all variable amount of lines between them and then do an action with it in bash. Example text: Total: text1 text2 Total: text3 Total:...
André Letterer's user avatar
-1 votes
5 answers
71 views

multiline grep search into separate files per occurence

I have a file as following: example.txt -1 15 1 0 0 11 -1.0000E+001 1.0000E+001 -1.0000E+001 2 0 0 11 1.0000E+001 1.0000E+001 ...
Honza S.'s user avatar
  • 101
1 vote
3 answers
78 views

How to tail continuously a log file that is being deleted and recreated?

I need to extract information from a log file that is deleted and recreated every time a program runs. After detecting that the file exists (again), I would like to tail it for a certain regexp. The ...
user2066480's user avatar
-1 votes
1 answer
42 views

I can't grep some inputrc string

bind -p |grep -E "\\e.\":" work but bind -p |grep -E "\\e\\C-.\":" don't work I tried a lot of combination
user3634569's user avatar
5 votes
1 answer
225 views

Is it possible to grep this output from gpg

Take the following command (real example) : ~$ gpg --edit-key [email protected] showpref quit (...) [ultimate] (1). Foo Bar <[email protected]> Cipher: AES256, AES192, AES, CAST5, 3DES AEAD: ...
ChennyStar's user avatar
  • 1,795
2 votes
2 answers
63 views

Listing a certain part of filenames and their contents

I have a Linux machine with BusyBox, which has a directory called /data/var/lib/connman.  That directory holds some directories that I'm not interested in.  But it contains many .config files that ...
Norbert's user avatar
  • 121
3 votes
1 answer
103 views

'ls name' and 'ls | grep name' with accent different

I am on Xigmanas (NAS freebsd). I'll explain the situation as simply as possible: :; set | egrep 'LC_A|LANG' GDM_LANG=fr_FR.UTF-8 LANG=fr_FR.UTF-8 LC_ALL=fr_FR.UTF-8 SLIM_LANG=fr_FR.UTF-8 :; ls -i ...
Dhénin Jean-Jacques's user avatar
1 vote
4 answers
167 views

Use sed or grep in bash script to check if file ends with specific string

I have a file called output.txt on my ubuntu server, how do I use sed or grep to check if the last two characters in the file are "nt" The text in the file is below, I expect my if statement ...
user23376904's user avatar
0 votes
5 answers
159 views

How to add content to a file before the last } character using Busybox utilities?

There is a file with contents { "first_name": "John", "last_name": "Smith", "is_alive": true, "age": 27, "address": { ...
Maxim's user avatar
  • 119
1 vote
1 answer
232 views

GREP error: warning: cannot select font 'i'

I am in the process of learning the usage of iscsiadm and somehow I noticed a strange behavior of grep. Attempting to run the following grep command man iscsiadm | grep "aia" results in ...
Cane's user avatar
  • 13
0 votes
1 answer
51 views

Find all the folders that are concealed using 'chflags'

I have concealed some folders on my laptop using chflags: chflags hidden hide-me And I don't remember where exaclty these folders are located. How is it possible to find all of them? (Probably by ...
jsx97's user avatar
  • 71
-4 votes
4 answers
212 views

Why does grep ignore the leading '.'?

I am trying to find a string in a web page downloaded w/ curl. I am using grep to find the string matching a regular expression pattern. Following is the string I am trying to find: ./download/file....
Seamus's user avatar
  • 3,062
0 votes
1 answer
67 views

How to add an exact-match flag to the following git + sed function?

I want to create a bash function where you can do a sed find and replace while ignoring the files and folders in .gitignore. I also want to be able to add any git grep flags to the command. For ...
wyc's user avatar
  • 143
0 votes
0 answers
124 views

How to Identify column names in terminal commands

Sometimes its useful to select/de-select specific columns from a command output data, but the columns are not always listed by name in the manpages. How can we find the names? For example Running two ...
raquel's user avatar
  • 11
-1 votes
3 answers
94 views

How to use a variable in a command inside of a bash file

I use this command directly on our redhat linux server 8.8 and it's working correctly and I get the result I want: grep '01-FEB-2024' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ...
TimLer's user avatar
  • 101
0 votes
2 answers
55 views

Excluding two kind of directories using regular expressions with grep

This SE answer made me realize I can exclude directories using regular expressions with grep. But it's not working for me when using |: results=$(grep --color=always -rnF "$searchTerm" . --...
wyc's user avatar
  • 143
-1 votes
1 answer
71 views

As soon as I touch a new file, my ls command with grep stops working [duplicate]

I'm trying to find all the files in my home directory with a specific extension. If I only have one instance of the file extension, the ls command works perfectly fine, but as soon as I touch a new ...
Gabriel Gavrilov's user avatar
0 votes
2 answers
109 views

Why using grep for some netstat commands require sudo priv?

System: Ubuntu 20.04.06 net-tools 2.10-alpha grep (GNU grep) 3.4 If I run netstat without sudo I see port information and no process information. This is expected as process information requires ...
Dave's user avatar
  • 621
1 vote
6 answers
162 views

GREP matching 6-7 digits within other data

I am trying to create a Regular Expression that will match a string of digits that is 6 or 7 digits long. [0-9]{6,7} This works but i dont want a match in strings that are longer than 7 digits. Please ...
pt-t's user avatar
  • 25
1 vote
3 answers
122 views

print a text block / lines between pattern using grep or awk

My file file.txt looks like this: [NamesA] Andreas Alex [NamesB] Bernd Bruno [NamesC] Casper [NamesD] Doris I would like accomplish the following 3 different outputs, using grep or awk to use it ...
AKSNET's user avatar
  • 13
0 votes
3 answers
87 views

sed command gets me error Label too long: on solaris

Given database name oltt206 or DB01 i wish to extract its respective username, password and connection string from the xml below: wladmin@myremhost:/tmp$ cat /web/bea_apps/uat/Tomcat_Home_v9.0.56/...
Ashar's user avatar
  • 511
0 votes
0 answers
33 views

Search a binary file for a list of 500 000 binary patterns

I have a list of binary "strings" in a file delimited by newlines. I'd like to use that to search another binary file to check which of these patterns the binary files contains and at which ...
PaperTsar's user avatar
  • 181
0 votes
0 answers
113 views

grep the output of FFmpeg

I can use grep to manipulate the output of all applications i use (or do something with sed or other tools). This doesn't work with FFmpeg. This is the output when i convert an audio file: ffmpeg ...
fmeier's user avatar
  • 331
4 votes
4 answers
473 views

Grep for lines starting with strings from a pattern file

I have a file (pattern file) I would like to feed into grep via -f, and I would like to find matches in another file (search file) where a string starts with that given pattern. For example: ...
ExecutionByFork's user avatar
0 votes
0 answers
24 views

Directly Replacing Text in Binary File [duplicate]

I have a compiled executable (binary) file - mybin - which grep indicates contains a positive match with a given text string - Cats. grep "Cats" mybin Binary file mybin matches If I use the ...
Mark's user avatar
  • 101
-1 votes
3 answers
121 views

grep 20k words from a file

i have 5000 files in a folder. these files are named XX0000001 to XX0005000 i am trying to get words from each of these files, and grep them and the next line in another file (target.txt) i have about ...
kaur's user avatar
  • 23
14 votes
6 answers
2k views

How to recursively list all files whose entire content is exactly "\n"

I have some failed experiment result files, and their contents are exactly a single \n (newline). I would like to list them all (perhaps with something like find or grep), to know what are the files ...
FxMySz's user avatar
  • 144
0 votes
1 answer
137 views

Why does grep not find MAC addresses and host names in Linux?

I have a file mac-hosts containing MAC addresses and their associated host names: e4:5f:01:21:79:01 PF3 e4:5f:01:21:79:03 PF3-BR0 e4:5f:01:21:79:be PF2 e4:5f:01:21:79:c0 PF2-BR0 I want to get a count ...
FKEinternet's user avatar
-1 votes
1 answer
150 views

Insert text between two lines

I am trying to insert one line between the below lines auth sufficient pam_unix.so nullok try_first_pass <insert the text here> auth requisite pam_succeed_if.so uid >= ...
Hari's user avatar
  • 1
-1 votes
2 answers
95 views

Grep the word with multiple spaces

I am trying to grep the below text from a file and trying to uncomment the same with sed command. please help #auth required pam_wheel.so use_uid Need to grep and remove # for exact ...
Hari's user avatar
  • 1

1
2 3 4 5
101