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
330 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
643k 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
68 votes
8 answers
63k 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,202
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
1k 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,733
0 votes
3 answers
622 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
553 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
2 votes
1 answer
190 views

Not able to extract with grep

> <img alt="Citizen Kane Poster" title="Citizen Kane Poster" src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTQ2Mjc1MDQwMl5BMl5BanBnXkFtZTcwNzUyOTUyMg@@._V1_UX182_CR0,0,182,268_AL_....
Swastik Udupa's user avatar
0 votes
5 answers
98 views

Regex to match text between two delimeters?

Heres an example of the things I need to match on a request that I have stored as a text: [{"id":"896","name":"TinyAuras","author_id":"654","author":"Kurisu</span></strong></span></a>","...
Ben's user avatar
  • 777
1 vote
3 answers
93 views

Rename batch of specific files using bash

Say I have a folder which contains files like this: a constant prefix and then an underscore and some description which is different for every file: constantnamehere_description1.doc ...
azal's user avatar
  • 1,250
0 votes
3 answers
149 views

How to verify the output of a command in shell?

I need to verify if a particular file system has the noexec option set. For example /dev/shm. I am running the command in the following manner: get_val=$(mount|grep /dev/shm ) if [[ -z get_val ]] ; ...
CoderBC's user avatar
  • 1,362
0 votes
1 answer
83 views

Parsing files to copy the ones that match my criteria

I have files that are to be copied and removed on different days and different times, and the criteria is part of the file's name. I was thinking of using Bash and regex to combine various variables ...
Paolo's user avatar
  • 2,211
1 vote
1 answer
67 views

"email ip" regex into log file

I have a logs file looking like: 'User_001','Entered server','[email protected]','2','','','0','YES','0','0',','0','192.168.1.1','192.168.1.2','0','0','0','0','0','0','0','0','0','1','0','','0','0','0','...
Giuseppe Pirlo's user avatar
0 votes
1 answer
48 views

How to capture from regex in bash?

I am running this piece of code so that I can match the branch name with a pattern and create port based on which: nano test.sh #!/usr/bin/env bash branch="3.2.1" re='([0-9]+)\.([0-9]+)\.(...
Amin Ba's user avatar
  • 2,154
0 votes
3 answers
26 views

Does exist more convenient manner to get the svn revision number output from svn log?

please see below : echo "r22543 | foobar | 2016-03-08 17:17:02 +0800 | 1 line" | egrep -o 'r[0-9]+' | egrep -o '[0-9]+' 22543 Does exist more convenient manner to get the svn revision number?
zhuguowei's user avatar
  • 8,349