Questions tagged [regular-expression]

Regular expressions are a means of matching a pattern of characters within a string.

Filter by
Sorted by
Tagged with
0 votes
1 answer
74 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
1 answer
70 views

regex: how come the trademark symbol matches to a-z?

Sorry if this is a repeat or basic question but it is hard to search for a ™. I'm writing a script to remove weird characters from file names. How come the trade mark symbol ™ matches [^a-z] ??? $ ...
codywohlers's user avatar
0 votes
1 answer
38 views

Using find with regular expression

I try to understand how to use the find command with regular expressions (macOS 14.4.1, Zsh 5.9). I have a directory with files such as note-red.png, note-yellow.png, (and other colors), folder-red....
jsx97's user avatar
  • 181
0 votes
1 answer
23 views

using ripgrep with regex including literal dollar symbol

Suppose I have a script containing something like VAR=${VAR1%.*} I'm looking for a command along the lines of rg "${.*%" to find it, but I can't get anywhere near. all of these fail rg &...
njamescouk'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 votes
1 answer
40 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
0 votes
2 answers
45 views

Are there reasons why \b is not supported in bash regexs? [duplicate]

AFAIK the \b metasequence indicating "word boundaries" is not supported in bash: if [[ $foo =~ .*\bWORD\b.* ]]; then Are there reasons why this is not supported? Imagine I write a patch/...
guettli's user avatar
  • 1,409
0 votes
1 answer
16 views

Using sed to filter output of rsync --itemize-changes -i [duplicate]

After using rsync --itemize-changes -i --recursive --checksum --dry-run to compare the contents of two drives, I got this kind of result: 2024/03/12 08:31:01 [15248] .d Backups/Phone/Pictures/...
the_redburn's user avatar
2 votes
5 answers
411 views

Search and replace regular expressions [closed]

I have a .txt file which is a collection of numbers. It looks like this: [...] 6 2 7 999 8 105 9 78 10 45 11 6666 [...] up to a 4-digit index. Now I want to import the numbers as a list in python. ...
Lereu's user avatar
  • 131
2 votes
1 answer
75 views

AIX - BASH REGEX INTO IF STATEMENTS = Segmentation fault (coredump)

Hello everyone and thanks for your support! I'm facing a problem while using REGEX inside a bash script through =~ operand. Environment: GNU bash, version 4.1.7(1)-release (powerpc-ibm-aix5.1.0.0) ...
omar.c's user avatar
  • 23
-4 votes
4 answers
183 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
  • 2,959
-1 votes
5 answers
146 views

add empty line before every line that contains certain characters

I have a lot of markdown files that contains something like this: * header A - item 1 - item 2 ** sub-header A1 ** sub-header A2 * header B - item 1 - item 2 ** sub-header B1 ** sub-...
GhostOrder's user avatar
0 votes
3 answers
70 views

Edit inside an HTML tag with ed(1)

Consider my humble hello.html file, edited with mighty ed: $ ed hello.html 28 ,p <title>Hello world!</title> What's your general approach to edit inside that title HTML tag (bonus if you ...
mbigras's user avatar
  • 3,120
0 votes
1 answer
101 views

Ansible - Regex in Fetch?

I'm building an ansible playbook to copy a checklist from this file and moving it to another file. I'm relatively new to ansible. Originally, I used the Copy plugin but saw Fetch may be more up my ...
shottypop's user avatar
0 votes
2 answers
54 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
  • 133
1 vote
5 answers
106 views

sed command to replace a word within a line following a pattern

I'm working with a file that looks like the following, containing with over 50,000 lines of gene IDs followed by their sequence: gene_A:3342234 CTCTTTCTTTTACGCCT gene_A:1244-5205 CTCTTTCTTTTACGCCT ...
bryophyta's user avatar
1 vote
6 answers
145 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
2 votes
2 answers
214 views

sed word boundaries: replace command macros with the commands

I inherited a body of code where "command macros" are used in place of the underlying command to be run, e.g., $TR is used in place of tr. I want to use sed to convert the command macros ...
FKEinternet's user avatar
-1 votes
1 answer
62 views

In a bash script, using =~, how do I match the regex ^#.*${new_user}?

Title basically says it all, but I can't figure it out for the life of me and getting confused by bash regular expression matching. This is the if statement I have in my bash script, but it keeps ...
geckels1's user avatar
  • 133
6 votes
1 answer
308 views

Why can't I print this regex range with ed(1)?

I'm totally mystified why I can't print this range with ed when there are two ranges—see file2.tf file—; but I can print when there is only one range—see file1.tf file—and I can print with the gsed (...
mbigras's user avatar
  • 3,120
0 votes
1 answer
32 views

Meaning of reg expression in drop.conf (Suricata)

I have this question since time ago, and I'm not able to understand it. In the sample config file for Suricata drop rules, drop.conf, appears this sample line: # Rules matching specifiers in this file ...
Ecofintech's user avatar
0 votes
1 answer
107 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
2 votes
2 answers
168 views

best / any way to count escapes in glibc regex(7) / GNU sed / grep / egrep Regular Expressions?

Given bash environment variable settings : $ declare -g bs=$'\\' bsbs=$'\\\\' q="'"; This Regular Expression will correctly match a sequence of single quote-("'")-ed text , where ...
JVD's user avatar
  • 115
1 vote
1 answer
44 views

Search and replace content

PIN A 1 1:3 0:8 0 0:0 PIN B 1 1:0 0 0:0 Z Z:0 PIN C 1 1:3 0:8 0 0:0 Z Z:0 I would like to change the content on PIN A & PIN C only without affecting PIN B to 0 0:3 Z 0:3 Can't seem to find a ...
JSL's user avatar
  • 11
0 votes
2 answers
129 views

Sed - How to replace two strings, but preserving what is in between them?

I am writing a shell script to convert some DokuWiki pages to MediaWiki format and vice versa. I'm having some troubles with footnotes. There is a plugin for DokuWiki that adds extended features to ...
Daniel's user avatar
  • 363
0 votes
1 answer
232 views

Start of the line with regex in Ubuntu 22.04's gedit text editor

I try to use regex such as ^ to find the start of the line in the gedit editor in Ubuntu 22.04 but it doesn't work. Also for $ as the end of the line. Other regular expressions such as \n,\d,\s work ...
trilisser's user avatar
  • 103
1 vote
1 answer
77 views

How to output regex matches as many-to-one combinations?

I'm trying to match two different text patterns in a single file and combine their results. Specifically, I have source code whose structure I want to understand by mapping events to their handlers, e....
Jan Wilamowski's user avatar
-1 votes
4 answers
246 views

AWK match exact value from comma separated column in brackets

So I need to find an exact number match from one column in a file. The input files is similar to the following: 33.xx 1111 0 0 0 some+text 12:12:12.9999 9999:090909 88 [11,22,33] 2020-12-12 12:12:...
Scott Nipp's user avatar
0 votes
1 answer
100 views

Whats the meaning of this sed command sed '/^[[:space:]]*$/d'

I came across this sed command in a script to compare a machine's local binaries to GTFObins binaries. for i in $(curl -s https://gtfobins.github.io/ | html2text | cut -d" " -f1 | sed '/^...
M4raa's user avatar
  • 13
0 votes
1 answer
227 views

Rename file in Mac OS Terminal using Regex or translate from Windows Script

I would like help with a shell script for macOS to rename files with a certain pattern. The script would handle only one file, not multiple. Here are three examples: a. Public Talks_ (189) Walking ...
Allex Valentin's user avatar
0 votes
2 answers
69 views

Why does bash regex fail for meta characters? [duplicate]

I am trying to do a bash script to check if input file name is of format name.json. The regx in bash doesn't work but it works with grep. file t1.sh echo "$1" regx="^[\w\d-]+[.]json$&...
preetam's user avatar
  • 117
1 vote
5 answers
125 views

How might I swap the remaining parts of lines (with the exception of first characters) with sed?

I have a file, fr.fc that represents flashcards used by hardv that I want to use to generate with sed a similar file, fr-swapped.fc %% This is a card set for hardv(1) %% Created at Feb 1, 1997 NEXT ...
John Smith's user avatar
2 votes
4 answers
322 views

linux + delete by bash script the unused/incorrect UUID number/s from fstab file

our goal is to create bash script that delete the unused / unnecessary UUID number/s from /etc/fstab file , brief background - in our labs , we have more then 500 RHEL servers , and we want to fix the ...
yael's user avatar
  • 13.2k
0 votes
0 answers
20 views

Using dkms's PATCH_MATCH to patch module code for kernels newer than 5.15

DMKS has the option to patch module code for kernels matching a particular regex. The manpage isn't very clear but digging around a bit confirms that the general syntax is: PATCH[0]="patch-foo....
RJVB's user avatar
  • 254
0 votes
1 answer
420 views

grep command, find words starting and ending with a letter

So I understand that if you want to match beginning of a word with a specific letter(s), you would use \<, ex, \<Aa. Vice versa for end of a word, \>. How would you combine these two commands ...
user22712878's user avatar
1 vote
4 answers
201 views

How to remove entire string that match specific pattern in unix txt file with a single command line

I would like to remove all the strings that contain "vcc". Example: s_regscan_ctrl_lab_2_regscan_ce[0] s_regscan_data_l_regscan s_t_regscan_data_tieoff_regscan vcc_cram_viort1_6_t ...
bg yeoh Yeoh's user avatar
-1 votes
2 answers
208 views

How to get complex regex to work in bash

The idea is to get a rudimentary check on input pattern for a url: $ ns='abc.def.com' $ reg_expr="\N*\.(\D{2}|\D{3})$" $ echo $reg_expr \N*\.(\D{2}|\D{3})$ $ [[ $ns =~ "$reg_expr" ]...
preetam's user avatar
  • 117
1 vote
2 answers
312 views

How does one use regex to check input between 0-5 in bash

What is the regex pattern for checking for a single digit number within a range? I am trying the following pattern which seems to work when tested on https://regex101.com/. pattern: \b([0-5])\b ...
preetam's user avatar
  • 117
1 vote
3 answers
68 views

How do I make sed delete a block of indented text below a non-indented line that also contains particular regexp, but not beyond?

I've been fighting with GPT, the sed documentation, and regex for almost my entire day. I'm trying to parse through files that contain cisco prefix-list configurations and print out the lists that ...
vessl921's user avatar
-1 votes
2 answers
107 views

allow display and or execution of web files but not direct url access using htaccess

What I want to Achieve is: I want to be able to display the (mp4 | jpg | ico) file types and execute the (js | css) file types on the browser only on my domain but I dont want them to directly access ...
genesis lubrigas's user avatar
3 votes
5 answers
766 views

Replace a block of spaces with a comma

I have a file in txt format that I want to convert to csv. Between each field there are blocks of spaces. The amount of spaces is not the same between every field. Is there a command with sed or awk ...
pwrsheller's user avatar
1 vote
2 answers
57 views

Shell one-liner for batch renaming music albums folders according to regexp – “zsh: missing identifier after `+'”

My music library consists of folders named after the following pattern : METAGENRE - Subgenre(s) - ARTIST - Album (year) I want to switch the year and album "tags" in the folders' names for ...
sylvainsab's user avatar
-1 votes
1 answer
288 views

Bash built-in regex vs sed and grep commands

Bash has built-in regex for pattern matching. Sed and egrep commands can also do this. What is the benefit to choose the built-in vs commands? I would like to know which one is faster and other ...
oldpride's user avatar
  • 231
1 vote
1 answer
109 views

get PID by name

I'm running an autopilot on a closed environment running Linux, and I've got a kernel thread whose priority I need to change. I'd prefer not to patch the kernel for this. This thread is created early ...
rsaxvc's user avatar
  • 150
-4 votes
4 answers
99 views

For lines matching in the first column, create a "X see also Y" list using second column

For wikidata I want to create QuickStatments to assign P1889 values for forts with identical names. This can be simplified to. For a file with: Fort George,Q12 Fort George,Q56 Fort George,Q678 Fort ...
vicarage's user avatar
0 votes
1 answer
38 views

nano unhighlight string if a quote is escaped

I'm trying to unhighlight string if one of the quotes is escaped. sh.nanorc regex is as follows: color brightyellow ""(\\.|[^"])*"" I'm having success with the closing quote ...
Multifix's user avatar
  • 113
1 vote
1 answer
73 views

Regular expression to search contents that contain qr in it?

grep -rlw . -e '%QR%' I am doing something like this. Anything could be before QR and anything could be after QR. It could be nothing as well. I am searching for file names containing QR inside in ...
achhainsan's user avatar
1 vote
4 answers
73 views

Find strings with several exclude-constraints on the beginning of the line

If I want to find all the "double-quoted" strings in files, I would use: grep -rnw . -e "\".*\"" but I want to exclude all the lines that begin with some text. For ...
Mark's user avatar
  • 723
0 votes
1 answer
124 views

Transforming a filename with 'tr' using RegEx doesn't work

I want to use the tr command to rename something like filename.ext to someName.ext. To do that I've tried echo "filename.ext" | tr -c ".a-z" "someName"` to replace the ...
Abhishek A Udupa's user avatar
5 votes
4 answers
1k views

Select everything between two timestamps in a log file

awk '/10:..:/, /13:..:/' server.log > /tmp/awktmp I tried this command as someone gave me. It worked for me to find logs between 10:00 AM to 13:00 PM but I don't understand it fully. Please tell ...
achhainsan's user avatar

1
2 3 4 5
56