Skip to main content

GetSubStr

Utility that allows you get substring of each stdout line based on regexp.

GetSubStr v1.0.6 - gets substring of each stdout line based on regexp.

positional arguments:
  regexp_pattern        Regexp pattern

optional arguments:
  -h, --help            show this help message and exit
  -l CUT_LEFT, --left-cut CUT_LEFT
                        Cut N chars from left side of result
  -r CUT_RIGHT, --right-cut CUT_RIGHT
                        Cut N chars from right side of result
  --lwrap L_WRAP        Wrap results from left side by specified char(s)
  --rwrap R_WRAP        Wrap results from left side by specified char(s)
  -s, --strip           Strip spaces from left and right side of result
  -j JOIN_RESULTS, --join-results JOIN_RESULTS
                        Join all results with specified char(s)
  --join-matches JOIN_MATCHES
                        Join more regexp matches with specified char(s). Default is TAB \t
  --reverse-matches     Reverse order of matches
  --split SPLIT         Split result by specified string.
  --split-after SPLIT_AFTER
                        Split result by specified string after each X match. For example split after every 5th ',' uccurence.
  -f FIND_REPLACE, --find-replace FIND_REPLACE
                        Find string and replace it with another string. It have to be defined in following format "find::replace"
  -o OUTPUT_FORMAT, --output-format OUTPUT_FORMAT
                        Output format for matches (Best if you are using regexp groups). ex: "myId:{0} yourId:{1}"
  -i, --ignore-errors   Ignore errors caused regexp.

example #1:

printf "**** Error while updating article content id=498 ****\n**** Error while updating article content id=512 ****\n" \
| getsub "id\=\d+" -l 3 -j "," --lwrap "\"" --rwrap "\""

output:

"498","512"

example #2 - grep lines from common logfile:

> grep "Error" error.log | getsub "id\=\d+" -l 3 -j "," --lwrap "\"" --rwrap "\""

output:

"680093","679962","678612","678313","678043","677973","676873","676431","675696"

example #3 - custom output format:

printf "123 456\n789 012" | getsub "(\d+) (\d+)" -o "i='{0}'...j='{1}'"

output:

i='123'...j='456'
i='789'...j='012'

Installation

sudo python3 setup.py install

or

pip3 install GetSubString

or without PIP

wget https://gitlab.com/alda78/getsubstr/-/archive/master/getsubstr-master.tar \
&& tar -xf getsubstr-master.tar \
&& cd getsubstr-master/ \
&& sudo python3 setup.py install \
&& cd ../ \
&&  sudo rm -rf getsubstr-master

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GetSubString-1.0.11.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

GetSubString-1.0.11-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file GetSubString-1.0.11.tar.gz.

File metadata

  • Download URL: GetSubString-1.0.11.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for GetSubString-1.0.11.tar.gz
Algorithm Hash digest
SHA256 1a3fe5552e0d5d3911dd9e3e9c8241c31fce1964ad1d2ca04aee1e38733e08b0
MD5 967b1c858409fce028c5af98e6804a1b
BLAKE2b-256 1e7497417ddb6bbbf5caa5cd363ad012346db8f36815dc1a14d401243062a91d

See more details on using hashes here.

File details

Details for the file GetSubString-1.0.11-py3-none-any.whl.

File metadata

  • Download URL: GetSubString-1.0.11-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for GetSubString-1.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 0c1a4a42d8f4c54b368701f957f7ed7b9e688e45e246c2d7473d2da2400cd298
MD5 6b290d56e4bbb08c194c2726fd448ed8
BLAKE2b-256 1cf745e697b45fa406f731e179e42acf350d45c4033d51f766de598692bfc23e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.11 This release

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

3 files

1.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page