I am trying to do some formatting on output data in a script and not positive how to do Left Right justify as well as width. Can anyone point me in the right direction?
相关问题
- How to get the return code of a shell script in lu
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- “command not found” errors in expect script execut
- Python script using subprocess and xclip hangs if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- Why does popen() invoke a shell to execute a proce
- In IntelliJ IDEA, how can I create a key binding t
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Is there a non-java, cross platform way to launch
- Launch interactive SSH bash session from PHP
- Generate disk usage graphs/charts with CLI only to
you can use printf. examples
tools like awk also has formatting capabilities
You're not being very clear, but the easiest way is probably to just use
printf()
(the shell command, not the C function of the same name).Left align is kind of trivial, to get right align you can use
printf
and the envrironment variable$COLUMNS
like that:You can do it using pure bash:
Output is:
So the two things you need to know is ${#var} will get the length of the string in var, and ${var:x:y} extracts a string from x to y positions.
You may need a recent version (tested on GNU bash 3.2.25)
EDIT: Come to think of it, you can do it like this:
Here is a Perl script that does full justification and hyphenation.
Here is a diff to add a left margin feature to that script:
Pipe it through
fmt
? Not actually bourne shell specific, but still...