https://github.com/v2e4lisp/mch
match line
https://github.com/v2e4lisp/mch
Last synced: 10 months ago
JSON representation
match line
- Host: GitHub
- URL: https://github.com/v2e4lisp/mch
- Owner: v2e4lisp
- License: mit
- Created: 2016-12-20T14:08:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-17T12:33:07.000Z (over 9 years ago)
- Last Synced: 2025-01-16T03:51:35.764Z (over 1 year ago)
- Language: C
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
mch is a simple command for text manipulation.
mch reads from the stdin line by line, matching each one against the input pattern (specified by `-i`).
If a line is fully matched it will be printed out to the stdout based on the output pattern (specified by `-o`).
In the input pattern, everything except `$` is matched as it is, while `$` matches 0 or more chars until it meets its following char.
For exmaple, the `$` in `$c` matches anything as long as it's not `c`.
In the output pattern, `$` followed by a number refers to the string that is matched by its counterpart in the input pattern.
The number works as an index starting from 1; `$0` refers to the whole line. As in the input pattern everything else is what it is, no escape is available.
mch doesn't support unicode.
```
# Example: extract uri from nginx access log
$ echo '123.65.150.10 - - [23/Aug/2010:03:50:59 +0000] "POST /wordpress3/wp-admin/admin-ajax.php HTTP/1.1" 200 2 "http://www.example.com/wordpress3/wp-admin/post-new.php" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.25 Safari/534.3"' | mch -i '$ $ $ [$] "$ $ $"$' -o '$6'
/wordpress3/wp-admin/admin-ajax.php
# Example: csv -> tsv (tab is entered by C-v [TAB])
$ echo 'col1,col2,col3' | mch -i '$,$,$' -o '$3 $1'
col3 col1
```