All Questions
Tagged with shell-script regular-expression
248 questions
2
votes
3
answers
106
views
Printing a specific section everytime search results are matched
I have a pretty basic text file on a Linux machine that has stuff like Chapters, Dialogues and References.
This is what it looks like
Chapter: 1 One: Birds and Trees
Birds are beautiful and trees ...
0
votes
1
answer
132
views
How to run a command that requires input/output location on all folders in a directory, while correspondingly naming the new output folders?
For context, I have some experience with Unix and basic commands, but I'm seriously struggling to conceptualize more complex manipulations of files. Essentially, I have this command I want to run from ...
1
vote
1
answer
103
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
492
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 &...
0
votes
1
answer
198
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 '/^...
0
votes
2
answers
144
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$&...
1
vote
4
answers
525
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
...
-1
votes
2
answers
465
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" ]...
1
vote
2
answers
852
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
...
4
votes
5
answers
1k
views
Cut the release versions from file in linux
I have a file that contains a list of OS packages with their release versions. I only need the package names and don't need the release versions.
How can I achieve this using Linux commands or any ...
0
votes
2
answers
769
views
Regular Expression Bracket Expression with bash
I want to write a regular expression that only allows a user to enter an input which contains alphanumeric characters, underscores, periods, dashes, and plus signs.
In a bash script, I have:
VALID=&...
0
votes
1
answer
164
views
Find files (ignoring extension) that may contain spaces, based on a supplied text file containing this list
With my limited knowledge of Linux tools, I hit a wall.
Because my list of files contains spaces (space character), the "find" command fails to find any hits, but does not produce any errors....
2
votes
5
answers
361
views
Extract lines from indented output
I'd like to parse parses the output below (from ddcutil) in a shell command:
Model: MQ780
MCCS version: 2.1
Commands:
Op Code: 01 (VCP Request)
Op Code: 02 (VCP Response)
Op Code: 03 (VCP Set)...
0
votes
1
answer
696
views
Using Bash "=~" operator with WHILE instead of UNTIL loop
I'm writing some shell script which asks the user for a domain name. I'd like to prompt the user for input in a loop, and write an error message, if the input is not a valid domain name.
Basically, ...
0
votes
2
answers
719
views
Bash check if item in list not behaving as expected
I am trying to write a script which has a condition based on a variable appearing in a list:
#!/bin/bash
LIST=`ls`
function listcontains() {
[[ $1 =~ (^|[[:space:]])$2($|[[:space:]]) ]] &&...