Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ryuichiueda/opy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.0
Choose a base ref
...
head repository: ryuichiueda/opy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Nov 3, 2019

  1. Copy the full SHA
    38c9165 View commit details

Commits on Nov 6, 2019

  1. Copy the full SHA
    5c2092c View commit details

Commits on Nov 9, 2019

  1. Update the man file

    ryuichiueda committed Nov 9, 2019
    Copy the full SHA
    672981c View commit details

Commits on Nov 10, 2019

  1. Refactor

    ryuichiueda committed Nov 10, 2019
    Copy the full SHA
    12129bb View commit details
  2. Refactor

    ryuichiueda committed Nov 10, 2019
    Copy the full SHA
    20ff787 View commit details
  3. Refactor

    ryuichiueda committed Nov 10, 2019
    Copy the full SHA
    2c0014f View commit details
  4. Refactor

    ryuichiueda committed Nov 10, 2019
    Copy the full SHA
    93a07ff View commit details
  5. Refactor

    ryuichiueda committed Nov 10, 2019
    Copy the full SHA
    25b97b9 View commit details
  6. Refactor

    ryuichiueda committed Nov 10, 2019
    Copy the full SHA
    9624400 View commit details
  7. Fix a name

    ryuichiueda committed Nov 10, 2019
    Copy the full SHA
    95b249c View commit details

Commits on Nov 12, 2019

  1. Explain options

    ryuichiueda committed Nov 12, 2019
    Copy the full SHA
    0b862b9 View commit details

Commits on Nov 13, 2019

  1. Add examples

    ryuichiueda committed Nov 13, 2019
    Copy the full SHA
    ad47877 View commit details
  2. Remove overlap

    ryuichiueda committed Nov 13, 2019
    Copy the full SHA
    5946cdf View commit details
  3. Remove join and dropjoin

    ryuichiueda committed Nov 13, 2019
    Copy the full SHA
    014ea43 View commit details
  4. Remove overlappings

    ryuichiueda committed Nov 13, 2019
    Copy the full SHA
    81687d9 View commit details
  5. Copy the full SHA
    400544a View commit details

Commits on Nov 30, 2019

  1. Create main.yml

    ryuichiueda authored Nov 30, 2019
    Copy the full SHA
    a554d1e View commit details
  2. Add install of bats

    ryuichiueda authored Nov 30, 2019
    Copy the full SHA
    023af3c View commit details
  3. Add sudo

    ryuichiueda authored Nov 30, 2019
    Copy the full SHA
    12fb996 View commit details
  4. Add install of numpy

    ryuichiueda committed Nov 30, 2019
    Copy the full SHA
    2d646b6 View commit details
  5. Change install way of pip

    ryuichiueda committed Nov 30, 2019
    Copy the full SHA
    6a92909 View commit details

Commits on Dec 30, 2019

  1. Fix some words

    ryuichiueda committed Dec 30, 2019
    Copy the full SHA
    9b83ff9 View commit details
  2. Copy the full SHA
    358cffc View commit details

Commits on Jun 29, 2020

  1. Copy the full SHA
    4f0dd2c View commit details
  2. Fix

    ryuichiueda committed Jun 29, 2020
    Copy the full SHA
    065030b View commit details

Commits on Jul 16, 2020

  1. Inhibit a warning message on pipefail

    sys.exit() throws an exception on pipefail. In this case, opy gave a
    warning message and finished with the exit status 120. Since I want to
    make opy ignore PIPEFAIL, I have replaced sys.exit() to os._exit().
    
    ```
    $ yes aho | opy '[F1]' | head
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
    BrokenPipeError: [Errno 32] Broken pipe
    $ echo ${PIPESTATUS[@]}
    141 120 0
    $ yes aho | opy '[F1]' | head
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    aho
    $ echo ${PIPESTATUS[@]}
    141 0 0
    ```
    ryuichiueda committed Jul 16, 2020
    Copy the full SHA
    172eb08 View commit details

Commits on Jan 1, 2021

  1. Support JSON

    ryuichiueda committed Jan 1, 2021
    Copy the full SHA
    010099a View commit details
  2. Add help

    ryuichiueda committed Jan 1, 2021
    Copy the full SHA
    9e62c13 View commit details
  3. Add an example

    ryuichiueda committed Jan 1, 2021
    Copy the full SHA
    f210a33 View commit details
  4. Add the yaml mode

    ryuichiueda committed Jan 1, 2021
    Copy the full SHA
    103e742 View commit details
  5. Copy the full SHA
    3064871 View commit details
  6. Fix

    ryuichiueda committed Jan 1, 2021
    Copy the full SHA
    4433ba3 View commit details

Commits on Jan 3, 2021

  1. Copy the full SHA
    ab95856 View commit details
  2. Update README and man

    ryuichiueda committed Jan 3, 2021
    Copy the full SHA
    cbabe6e View commit details
  3. Fix the example

    ryuichiueda committed Jan 3, 2021
    Copy the full SHA
    a19aed7 View commit details
  4. Fix

    ryuichiueda committed Jan 3, 2021
    Copy the full SHA
    8c0c82b View commit details

Commits on Feb 7, 2021

  1. Fix the version

    ryuichiueda committed Feb 7, 2021
    Copy the full SHA
    3cad83d View commit details

Commits on Jul 2, 2021

  1. Add csv tree mode

    ryuichiueda committed Jul 2, 2021
    Copy the full SHA
    67e6f28 View commit details
  2. Update README.md

    ryuichiueda authored Jul 2, 2021
    Copy the full SHA
    276ccc2 View commit details
  3. Update README.md

    ryuichiueda authored Jul 2, 2021
    Copy the full SHA
    13ccbe6 View commit details
  4. Merge README

    ryuichiueda committed Jul 2, 2021
    Copy the full SHA
    b190a30 View commit details

Commits on Jul 3, 2021

  1. Release xlsx feature

    ryuichiueda committed Jul 3, 2021
    Copy the full SHA
    92902f3 View commit details
  2. Fix

    ryuichiueda committed Jul 3, 2021
    Copy the full SHA
    54ba6ef View commit details
  3. Fix the test

    ryuichiueda committed Jul 3, 2021
    Copy the full SHA
    29c6ee9 View commit details
  4. Fix

    ryuichiueda committed Jul 3, 2021
    Copy the full SHA
    4e031d0 View commit details
  5. Remove travis settings

    ryuichiueda committed Jul 3, 2021
    Copy the full SHA
    fa5c01d View commit details
Showing with 313 additions and 344 deletions.
  1. +19 −0 .github/workflows/main.yml
  2. +0 −9 .travis.yml
  3. +73 −38 EXAMPLES.md
  4. +26 −18 README.md
  5. +118 −91 opy
  6. +32 −6 opy.1
  7. +45 −182 test
  8. BIN testdata/test.xlsx
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
- name: Set up and test with Python ${{ matrix.python-version }}
run: |
sudo apt-get install python3-pip bats
pip3 install numpy pandas openpyxl
./test
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

111 changes: 73 additions & 38 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
@@ -78,15 +78,6 @@ $ opy 'B:[1+1]'
2
```

### import of modules

```
$ seq 1 3 | opy -m math '[ F1*math.pi, math.sin(F1) ]'
3.141592653589793 0.8414709848078965
6.283185307179586 0.9092974268256817
9.42477796076938 0.1411200080598672
```

### dynamic load of modules

```
@@ -137,20 +128,6 @@ $ seq 10 | opy 'r_("[24680]", F1)'
10
```

* field selection

```
$ echo {1..10} | opy '[join(F,[2,3,4,6,7,8])]'
2 3 4 6 7 8
```

* field drop

```
$ echo {1..10} | opy '[dropjoin(F0,[2,3,5])]'
1 4 6 7 8 9 10
```

### input from file

```
@@ -174,33 +151,91 @@ $ seq 10 | opy 'NR%2:{L.append(F1)};E:[L]'
[1, 3, 5, 7, 9]
```

## use of scipy

* integrate

```
opy 'B:{from scipy import integrate};B:{def f(x): return 2*x};B:[integrate.quad(f,0,5)]'
(25.0, 2.7755575615628914e-13)
```

## options

* `--help`: show help
* `-m <modules>`: load modules
* `-s`: string mode
* prohibit automatic number conversions.
* `-i, -o`: input/output field separator

* `-c`: read data as CSVs

```
$ echo '1,2,3,4,5' | opy -i , '[F2]'
2
$ echo '1,2,3,4,5' | opy -i , -o x '[Fs(2,4)]'
2x3x4
$ echo 'a,"b,","c"""' | opy -c '[F1,F2,F3]'
a b, c"
```

* `-C`: output data with a CSV format

```
$ echo '1 2 3' | opy -C True
"1","2","3"
$ echo '1 "2,3" 3 "' | opy -C True
"1","""2,3""","3",""""
```

* `-s`: treat numbers from input data as strings



* `-i`: separators change input field separators

```
$ echo 100 JPY | opy '[F1+F2]'
(error!!)
$ echo 100 JPY | opy -s '[F1+F2]'
100JPY
```

* `-I`: regex input field separator
* `-I`: separators change input field separators with a regular expression


```
$ echo a33b313c | tr ' ' , | opy -I '\d+' '[Fs(1,3)]'
$ echo a,b@c | opy -I '[,@]' '[F1,F2,F3]'
a b c
```

## use of scipy
* `-m`: modules import modules

```
$ opy -m numpy 'E:{print(numpy.pi)}'
3.141592653589793
$ opy -m math,numpy 'B:[math.e,numpy.e]'
2.718281828459045 2.718281828459045
```


* `-o`: separators change output field separators

* integrate

```
opy 'B:{from scipy import integrate};B:{def f(x): return 2*x};B:[integrate.quad(f,0,5)]'
(25.0, 2.7755575615628914e-13)
$ echo a,b@c | opy -I '[,@]' -o '=' '[F1,F2,F3]'
a=b=c
```

* `-v`: `<variable>=<string>` define a variable from a string on the shell

```
$ a=abc
$ opy -v "b=$a" 'B:[b*2]'
abcabc
```

* `-t <json/yaml/xml>`: read a json/yaml/xml file and set the data to an object "T".

```
$ echo '{"hoge":["a","b"]}' | opy -t json '[*T["hoge"]]'
a
b
$ echo -e 'aho:\n boke: ["a","b"]' | opy -t yaml '[*T["aho"]["boke"]]'
a
b
$ echo -e '<?xml version="1.0" encoding="utf-8"?>\n<foo>bar</foo>' | opy -t xml '[e.text for e in T.iter("foo")]'
bar
```

44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@

a Python wrapper that works like AWK or rb command

[![Build Status](https://travis-ci.org/ryuichiueda/opy.svg?branch=master)](https://travis-ci.org/ryuichiueda/opy)

## example of use

```
@@ -17,6 +15,17 @@ $ seq 3 | opy '[math.sin(F1)]'

## install

### the simplest way

You can install `opy` with

```
$ chmod +x opy
$ sudo cp opy /usr/local/bin/ # Please check PATH.
```

since `opy` is an independent script file.

### make

The `opy` file and its manual are copied to `/usr/local/bin/` and `/usr/local/share/man/man1/` respectively with the following command.
@@ -25,31 +34,30 @@ The `opy` file and its manual are copied to `/usr/local/bin/` and `/usr/local/sh
$ sudo make install
```


### homebrew

The version remains old because I don't have a Mac PC anymore...

```
$ brew tap ryuichiueda/oneliner-python
$ brew install oneliner-python
```

## options

See [EXAMPLES.md](./EXAMPLES.md)

* `-b`: buffer the standard output
* `-c`: read each line as CSV data
* `-C`: output data with a CSV format
* `-s`: treat numbers from input data as strings
* `-i <separator>`: separators change input field separators
* `-I <separator>`: separators change input field separators with a regular expression
* `-m <module>`: modules import modules
* `-o <separator>`: separators change output field separators
* `-v <variable>=<string>`: define a variable from a string on the shell
* `-t <json/yaml/xml/csv/xslx>`: tree mode (read a json/yaml/xml/csv/xslx file entirely and set the data to an object "T".)
* `--help`: show help
* `-m <modules>`: load modules
* `-s`: string mode
* prohibit automatic number conversions.
* `-i, -o`: input/output field separator

```
$ echo '1,2,3,4,5' | opy -i , '[F2]'
2
$ echo '1,2,3,4,5' | opy -i , -o x '[F2,F3,F4]'
2x3x4
```

* `-I`: regex input field separator

```
$ echo a33b313c | tr ' ' , | opy -I '\d+' '[*F[1:]]'
a b c
```
Loading