Skip to main content

All Questions

-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
user3634569's user avatar
-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-...
GhostOrder's user avatar
1 vote
1 answer
112 views

How to delete a string in my files?

So I want to match all below then remove those lines of string. [MTT-5634](https://my.atlassian.net/browse/MTT-5634) [MCC-123](https://my.atlassian.net/browse/MCC-123) [MTT-7965]: https://my.atlassian....
Beelzebub's user avatar
0 votes
2 answers
1k views

How to delete everything before the occurrence of a regex pattern per line in a bash variable

I've got a bash variable containing several lines of text, which includes IP addresses, and I need to remove 'everything' before the last IP address occurrence in the same line. This: 43.12.40.53 ...
Damon Hill's user avatar
3 votes
3 answers
12k views

Modifying a shell variable with regex (bash)

I have a shell variable for example. a="big little man". How do I use regex in bash print out the variable with only the middle word capitalized? (big LITTLE man) I can do it by separating the ...
Vaish MK's user avatar
  • 133
0 votes
1 answer
625 views

String validation using regex posix class

I'm trying to build validation for an address field in a file The file is like so; 123 Strata Ln. 15 138th Ave 27 Hilltop Dr. Apt. 7 F52 Milk Ln. 156A Fantastic St. 56 sample Ln. These are the ...
Duck Dodgers's user avatar
1 vote
1 answer
294 views

Replace literal space with regex space

I want to change a string from This is a string to This\sis\sa\sstring but tr is not working for me no matter if I escape the \ or not string="This is a string" regex=$(echo "$string" | tr " " "\\s"...
myol's user avatar
  • 313
6 votes
1 answer
8k views

Why does the regex in bash works only if it is a variable and not directly? [duplicate]

So why does the following works i.e. prints out the match: THE_REGEX='^test\/version[0-9]+([.][0-9]+)+$' if [[ "$SOME_VAR" =~ $THE_REGEX ]]; then echo "Match!" fi But the following does NOT: if [...
Jim's user avatar
  • 1,459
6 votes
2 answers
13k views

String pattern-matching with =~

I have problems to understand the string pattern matching with =~ in bash. I wrote following function (don't be alarmed - it's just experimenting, not a security approach with md5sum): md5 () { ...
user unknown's user avatar
  • 10.8k
5 votes
2 answers
5k views

Extract Sub-Directory Path from Partially Known Directory

Lets say I've got the following directory structure: base/ | +-- app | | | +-- main | | | +-- sub | | | +-- first | | | | | +-- tib1.ear | ...
Darrel Holt's user avatar
21 votes
3 answers
6k views

Does bash support back references in parameter expansion?

I have a variable named descr which can contain a string Blah: -> r1-ae0-2 / [123], -> s7-Gi0-0-1:1-US / Foo, etc. I want to get the -> r1-ae0-2, -> s7-Gi0-0-1:1-US part from the string. ...
Martin's user avatar
  • 8,006
4 votes
1 answer
3k views

Bash regular expression pattern matching spaces, within double brackets test, using "~=" operator

Simply said, I just can't find a way to match a variable against some pattern containing spaces. Here is what I expected to work (echo 'ok' string) item='foobar baz' pat=".+bar baz" if [[ "$item" =~ ...
Stphane's user avatar
  • 341
13 votes
4 answers
14k views

How do I extract parts of a string to variables?

I have a line from some file like this: attempting to create a 512^3 level (with Dirichlet BC) using a 16^3 grid of 32^3 boxes and 800 tasks... I want to extract the 512^3, 16^3, 32^3 and 800 four ...
Yulong Ao's user avatar
  • 536
0 votes
2 answers
1k views

Bash regex string manipulation bug

I have an issue with bash and its regex match ability that I for now think is a bug in bash but could also be me having missed something obvious. I hope it is the latter. I have made this function in ...
galmok's user avatar
  • 101
1 vote
3 answers
1k views

Bash Combine Replacement and Sub String Extraction in One Step

For a string in this format: ./my-site.sub.domain.com I would like to remove the .,-, and /, and trim the remainder to 16 characters: mysitesubdomainc I've done this mysite="./my-site.sub.domain....
KM.'s user avatar
  • 2,264

15 30 50 per page