Using Python as awk alternative.
$ pip install awpie
Upper case all inputs:
$ printf 'apple\norange\n' | awpie 'print(line.upper())'
APPLE
ORANGE
Change orange to banana:
$ printf 'apple\norange\n' | awpie 'print(line) if line != "orange" else print("banana")'
apple
banana
$ awpie
Usage: awpie [--sep=separator] [--imports=module1,module2] [--begin='prog'] [--end='prog'] 'prog' [file ...]
Separator used to split a line, default value is blank.
Specify which modules will be imported before executing all codes. Can specify multiple modules like --imports=csv,tomlib
.
These modules are imported by default:
- collections
- fileinput
- functools
- getopt
- importlib
- itertools
- operator
- os
- sys
Codes that will be executed before processing all files.
Codes that will be executed after processing all files.
Codes that will be executed for every line.
File to process. Default is to read a stream from stdin
as the file.
Name | Type | Description |
---|---|---|
line |
str |
Current line. |
fields |
list[str] |
Result of line.split(sep) . sep can be specified in arguments. |
data |
dict |
An empty dict, can be used to store custom values. |
stdout |
sys.stdout . |
|
stderr |
sys.stderr . |
|
filename |
str |
Name of the file currently being read. |
fileno |
int |
File descriptor for the current file. |
lineno |
int |
Cumulative line number of the line that has just been read. |
filelineno |
int |
Line number in the current file. |
isfirstline |
bool |
Whether the line just read is the first line of its file or not. |
isstdin |
bool |
Whether the last line was read from sys.stdin or not. |
nextfile |
callable |
Close current file so that next iteration will be read from next file. |
close |
callable |
Close the sequence. |