Linked Questions

0 votes
3 answers
2k views

how to egrep after using egrep -o [duplicate]

I have a file called random.html with the following line(not the only line): blahblahblahblah random="whatever h45" blahblahblahblah I want to specifically only get whatever, so far i used the ...
user1880760's user avatar
-2 votes
1 answer
326 views

How to capture specific text with grep, in Bash Command Line? [duplicate]

I need to capture a specific string using grep, on Bash Command Line. I cannot use sudo install/apt-install to install any addition software/packages like jq. I am not using any Python Interpreter; ...
codermonkey321's user avatar
0 votes
0 answers
114 views

Parse netstat -s using regex in shell script [duplicate]

netstat -s gives output like below Tcp: 12345 active connections openings 34345345 passive connection openings 3434 failed connection attempts 54545 connection resets received 5 connections ...
Akshay Abhang's user avatar
-2 votes
1 answer
111 views

How can bash recognize regex groups? [duplicate]

I am trying to use regex to match a filename out of a path. #!/bin/bash regex=[^/]+?(?=.zip) path="/home/quid/Downloads/file.zip" if [[ $path =~ $regex ]] then echo "Found a match" echo $...
3leggedquid's user avatar
0 votes
0 answers
44 views

Bash script regex on parameter [duplicate]

I have a script like this: #!/bin/bash ...
vaso123's user avatar
  • 12.4k
411 votes
12 answers
641k views

How can I output only captured groups with sed?

Is there a way to tell sed to output only captured groups? For example, given the input: This is a sample 123 text and some 987 numbers And pattern: /([\d]+)/ Could I get only 123 and 987 output in ...
Pablo's user avatar
  • 29.1k
67 votes
8 answers
61k views

Grep - how to output only the content of a capturing group

I am trying to find a way for grep to output only the content of a capturing group. For instance, if I have the following file: hello1, please match me hello2, please do not match me I would like ...
Alice's user avatar
  • 1,192
3 votes
5 answers
5k views

Extracting string between two slashes using sed [duplicate]

I am trying to use sed to extract a specific string from a line within a file. Currently I am reading in a file with a while loop and searching for a specific string. When that string is found I am ...
user1161118's user avatar
3 votes
5 answers
1k views

Pass the matched value to a function, and replace with the return value

How would I get Bash to match a regular expression, but rather than replace the value with a constant string, it will instead pass the matched value to a function, and then get the value to replace ...
IQAndreas's user avatar
  • 8,360
1 vote
4 answers
1k views

Bash script for getting tag value

Is there any way to get value(Yes or No) if i only have tag("answer_yes" or "answer_no") which are described in a xml file. I want to get them using bash. <string tag="answer_yes" value="Yes"/> ...
Bozhidar Marinov's user avatar
2 votes
3 answers
999 views

Bash - Extract region from AWS arn

Very simple task: extract the region from an AWS arn. Example: arn:aws:lambda:eu-west-2:12345678912:layer:my-awsome-layer:3 I need to extract eu-west-2 I have a working regex for this: ^(?:[^:]+:){3}(...
Kappacake's user avatar
  • 1,907
0 votes
2 answers
2k views

regular expression with grep not working?

I am running cygwin, grep 2.21 on Windows 7. I am trying to get all tcp connections from netstat, so I run the following: netstat | grep -i "^(TCP|UDP)" Now, it returns nothing, but when I run ...
makansij's user avatar
  • 9,703
0 votes
3 answers
620 views

Get specific key value in log pattern using the shell script

My log file has below pattern :- tx=267c5660-c49a-4ae7-b5ae-c9d43e23b617, rh=163.172.0.0, userId=-1, requestComplete={ requestId=74421156932, entityResourceType=xyz, pageId=homePage, uri=/home/, ...
Amit's user avatar
  • 31.9k
1 vote
2 answers
550 views

How to add leading zero's to sequential file names

I have images files that when they are created have these kind of file names: Name of file-1.jpg Name of file-2.jpg Name of file-3.jpg Name of file-4.jpg ..etc This causes problems for sorting ...
Jack Dorn's user avatar
0 votes
2 answers
285 views

Grepping for the form action= part of html pages

I am trying to grep the parts of an html form, specifically the action part i.e. <form action = …. I originally tried: grep -E -e 'form\s*action\s*=.*[.]html' ./* but it did not work (despite the ...
Jim's user avatar
  • 19.3k

15 30 50 per page