CLI utility that parses and transforms text
Project description
About
CLI utility that parses and transforms text written in Python.
Pysed is a Python stream editor, is used to perform basic text transformations from a file. It reads text, line by line, from a file and replace, insert or print all text or specific area. Actually pysed is a passage of Python module ‘re’ in terminal.
Read more for Regular Expression Syntax
Installation
$ pip install pysed --upgrade
uninstall
$ pip uninstall pysed
Command Line Tool Usage
Options:
-h, --help display this help and exit
-v, --version print program version and exit
-r, --replace search and replace text
-l, --lines search pattern and print lines
-g, --highlight highlight and print text
-s, --stat print text statistics
--write write changes to file
Python regex flags
Syntax |
Python syntax, Meaning |
---|---|
I or IGNORECASE |
re.IGNORECASE, ignore case. |
M or MULTILINE |
re.MULTILINE, make begin/end {^, $} consider each line. |
S or DOTALL |
re.DOTALL, make . match newline too. |
U or UNICODE |
re.UNICODE, make {w, W, b, B} follow Unicode rules. |
L or LOCALE |
re.LOCALE, make {w, W, b, B} follow locale. |
X or VERBOSE |
re.VERBOSE, allow comment in regex. |
Usage Examples
$ cat text.txt
This is my cat,
whose name is Betty.
This is my dog,
whose name is Frank.
This is my fish,
whose name is George.
This is my goat,
whose name is Adam.
Replace text:
$ pysed -r "name" "surname" text.txt
This is my cat,
whose surname is Betty.
This is my dog,
whose surname is Frank.
This is my fish,
whose surname is George.
This is my goat,
whose surname is Adam.
Maximum replace text:
$ pysed -r "name" "surname" 2 text.txt
This is my cat,
whose surname is Betty.
This is my dog,
whose surname is Frank.
This is my fish,
whose name is George.
This is my goat,
whose name is Adam.
Add character to the beginning of each line:
$ pysed -r "^" "# " 0 M text.txt
# This is my cat,
# whose name is Betty.
# This is my dog,
# whose name is Frank.
# This is my fish,
# whose name is George.
# This is my goat,
# whose name is Adam.
Add character to the end of each line:
$ pysed -r "$" " <-" 0 M text.txt
This is my cat, <-
whose name is Betty. <-
This is my dog, <-
whose name is Frank. <-
This is my fish, <-
whose name is George. <-
This is my goat, <-
whose name is Adam. <-
Search and print lines:
$ pysed -l "name" text.txt
whose name is Betty.
whose name is Frank.
whose name is George.
whose name is Adam.
Highlight text:
$ pysed -g "name" "red" text.txt
This is my cat,
whose name is Betty.
This is my dog,
whose name is Frank.
This is my fish,
whose name is George.
This is my goat,
whose name is Adam.
Print statics text:
$ pysed -s text.txt
Lines: 8, Words: 32, Chars: 125, Blanks: 27
Use the argument "--write" in any case when you want to save the changes like:
$ pysed -r "name" "surname" text.txt --write
Use as piping:
$ echo "This is my cat, whose name is Betty" | pysed -r "cat" "dog"
This is my dog, whose name is Betty
$ echo "This is my cat, whose name is Betty" | pysed -r "[^\W]+" "-"
- - - -, - - - -
$ echo "This is my cat, whose name is Betty" | pysed -r "is" "IS" 1
ThIS is my cat, whose name is Betty
$ echo "910a13de57dfbdf6f06675db975f8407" | pysed -r "[^\d+]" ""
91013576066759758407
$ echo "/usr/local/bin" | pysed -r "/local" ""
/usr/bin
Please report Issues
Copyright
Copyright © Dimitris Zlatanidis
Linux is a Registered Trademark of Linus Torvalds.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pysed-0.5.0.tar.gz
.
File metadata
- Download URL: pysed-0.5.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10ad567674dc6239ec9bff38c2cf5cb80bee9597fa17cf9d9f1e1eac0ee0c380 |
|
MD5 | a95da05718c73b67c274397072693374 |
|
BLAKE2b-256 | 11be6d232f8c9dffbea6539a52b2ed9dbc5e0d2e808c02b949f08ab65a585851 |