Pjs
An awk-like command-line tool for processing text, CSV, JSON, HTML, and XML.
Install / Use
/learn @aduros/PjsREADME
pjs
pjs is a command-line tool for filtering and transforming text, similar to awk. You provide it
powerful one-line snippets written in vanilla JavaScript. It supports many input formats, including
plain text, CSV, JSON, HTML, and XML.
pjs works by generating a complete JS program from the provided script, and feeding it each line of
standard input. The statically generated program can be reviewed with --explain.
See the examples section below to see what pjs can do. For complete documentation, read
the manual or run man pjs.
Installing
Install the pjs command with npm:
npm install -g pjs-tool
If npm is not available on your environment, you can download a standalone
executable. You will still need node installed.
Examples
Click on an example to run it in your browser at the pjs playground.
Transforming Examples
Convert a file to upper-case:
cat input.txt | pjs '_.toUpperCase()'
Print the second field of each line (in this example, the PIDs):
Print all fields after the 10th (in this example, the process names):
ps aux | pjs '$.slice(10).join(" ")'
Remove trailing whitespace from each line in a file:
cat document.txt | pjs '_.replace(/\s*$/, "")'
Filtering Examples
Given a list of numbers, print only numbers greater than 5:
Given a list of numbers, print only even numbers:
Print the last 4 lines of a file (like tail):
seq 1 10 | pjs --after 'LINES.slice(-4).join("\n")'
Print every other line of a file:
cat input.txt | pjs 'COUNT % 2 == 1'
Given a list of filenames, print the files that actually exist:
cat filenames.txt | pjs 'fs.existsSync(_)'
Given a list of filenames, print the files that are under one kilobyte in size:
cat filenames.txt | pjs 'fs.statSync(_).size < 1000'
Summarizing Examples
Manually count the lines in the input (like wc -l):
cat input.txt | pjs '{ count++ }' --after 'count'
Same as above, but using the built-in COUNT variable:
cat input.txt | pjs --after 'COUNT'
Count the unique lines in the input:
cat input.txt | pjs --before 'let s = new Set()' '{ s.add(_) }' --after 's.size'
Manually sort the lines of the input (like sort)
cat input.txt | pjs --before 'let lines = []' '{ lines.push(_) }' --after 'lines.sort().join("\n")'
Same as above, but using the built-in LINES variable:
cat input.txt | pjs --after 'LINES.sort().join("\n")'
CSV Examples
Given a grades.csv file that looks like this:
name,subject,grade
Bob,physics,43
Alice,biology,75
Alice,physics,90
David,biology,85
Clara,physics,78
Print only the third column:
cat grades.csv | pjs --csv '$2'
Print the grades using the column header:
cat grades.csv | pjs --csv-header '_.grade'
Print the names of students taking biology:
[cat grades.csv | pjs --csv-header '_.subject == "biology" && _.name'](https://aduros.com/pjs/#%7B%22command%22%3A%22pjs%20--csv-header%20'.subject%20%3D%3D%20%5C%22biology%5C%22%20%26%26%20.name'%22%2C%22input%22%3A%22name%2Csubject%2Cgrade%5CnBob%2Cphysics%2C43%5CnAlice%2Cbiology%2C75%5CnAlice%2Cphysics%2C90%5CnDavid%2Cbiology%2C85%5CnClara%
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
346.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
346.8kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
