All Questions
Tagged with bash regular-expression
441 questions
0
votes
2
answers
84
views
How to Rsync anything with its name having exact number of consecutive digits
I have the following directories:
1
12
123
1234567
1234566
1234555
121
I want to rsync the directories with exactly 7 digits in the name. (That would be 1234567, 1234566, and 1234555 from the above ...
0
votes
2
answers
131
views
variable assignment doesn't create one same object at least for grep
The problem is as follows (Here I don't use find since it doesn't support double-asterisk wildcard **):
$ FILES=(foo/**/*.suffix bar/**/*.suffix2)
$ grep baz "${FILES[@]}" # works
# I use ...
0
votes
2
answers
44
views
Capture and print on the exact match from a file
I am trying to use grep to match only a specific part of a row in a file.
The file is a huge csv file with some columns containing json with commas so it is hard to figure out which column what I am ...
4
votes
4
answers
313
views
BASH - Find file with regex - Non-recursively delete number-only filenames in directory
I'm wanting to non-recursively delete all files in a directory where each filename contains only numbers, using only a single line of BASH.
I somehow accidentally ran a shell script with commented out ...
0
votes
1
answer
81
views
Why does this sed command not work with "?" and "+"?
I'm trying to filter IP addresses from the ip a command via sed. When I write inet6* it works. When I write inet6? it doesn't find the match.
With *:
$ ip a | sed -ne 's,^ *inet6* \([^ /]*\).*$,\1,p'
...
3
votes
2
answers
541
views
How do quotes work in bash regex regarding reserved characters?
Is there any special bash reserved characters in bash regex expression?
ex:
eg: if [[ $url =~ ^https:\/\/www\.youtube\.com\/playlist\?(.+&)?list= ]]; then echo "URL matches the regex"; ...
-2
votes
4
answers
205
views
Getting output of /usr/bin/time in CSV format
I am using gawk to parse the output of macos' /usr/bin/time into CSV format as shown below. The problem is that gawk is returning the 'involuntary context switches' value for 'voluntary context ...
0
votes
0
answers
30
views
Bash regular expressions with the character classes are not matching [duplicate]
I am trying out the example 6.8 Testing with Regular Expressions from Bash Cookbook. I am reproducing the example here.
My folder contents are as,
$ ls
Ludwig Van Beethoven - 01 - Allegro.ogg
Ludwig ...
0
votes
1
answer
150
views
AWK: regex is not processed when passed as a variable
Any suggestions? I read: Escape Sequences (The GNU Awk User’s Guide)
Representative Example
$ Filesystem='/dev/mapper/vgubuntu-Media'
$ FilesystemRegex="$(echo "${Filesystem}" | sed &...
1
vote
1
answer
96
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?
0
votes
1
answer
282
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 &...
-1
votes
1
answer
45
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
0
votes
2
answers
117
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/...
2
votes
1
answer
98
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)
...
-1
votes
5
answers
169
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-...