批处理实现文本内容居中显示 -shell
2017-09-06 19:29
561 查看
批处理实现文本内容居中显示
题目如下
有一个文本a.txt[Promise don’t come easy]
I should have known all along.
There was something wrong.
I just never read between the lines.
Then I woke up one day and found you on your way.
Leaving nothing but my heart behind.
What can I do to make it up to you.
Promises don’t come easy.
But tell me if there’s a way to bring you back home to stay.
Well I’d promises anything to you.
I’ve been walkin’ around with my head hanging down.
Wondrin’ what I’m gonna do.
‘Cause when you walked out that door.
要求,CMD原始窗口中,不调节窗口大小,居中显示文本内容。输出如下:
[Promise don't come easy] I should have known all along. There was something wrong. I just never read between the lines. Then I woke up one day and found you on your way. Leaving nothing but my heart behind. What can I do to make it up to you. Promises don't come easy. But tell me if there's a way to bring you back home to stay. Well I'd promises anything to you. I've been walkin' around with my head hanging down. Wondrin' what I'm gonna do. 'Cause when you walked out that door.
编写代码
#! /bin/bash # 输出具体数量空格后,输出内容 # 参数1:空格数量 # 参数2:内容 function printll() { i=1 while [ ${i} -lt $1 ] do let i++ printf " " done echo $2 } # 传入当前窗口列值 # 参数1 width=$1 file=./a.txt while read line do len=${#line} let w=(${width}-${len})/2 # 这里一定要加上引号,参数有空格会当做多个参数传入 printll ${w} "${line}" done < ${file}
执行命令
./test.sh ${COLUMNS}ps:窗口列值:${COLUMNS},宽值:${LINES}
运行结果
参考文档
样式输出:http://blog.csdn.net/fdipzone/article/details/9993961相关文章推荐
- 批处理实现文本内容居中显示的代码
- 自己编的shell脚本,实现备份文本内容(目的:学习交流)
- 纯css3 实现多行显示隐藏和文本垂直居中
- 字符串处理是许多程序中非常重要的一部分,它们可以用于文本显示,数据表示,查找键和很多目的.在Unix下,用户可以使用正则表达式的强健功能实现这些 目的,从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础
- 实现Label文本内容中电话号码特殊颜色显示并点击电话号码能拨打
- 重写TextView,实现圆形背景,文本居中显示
- shell脚本中echo显示内容带颜色的实现方法
- shell脚本--显示文本内容
- shell实现文本处理详解
- Java实现的比较两个不同的文本,在文本面板中显示不同文本的内容(完整源码)
- 对于单文本或者div的内容怎么在显示东西过多的情况下实现显示隐藏
- shell脚本中echo显示内容带颜色的实现方法
- 用SDK对话框实现改变背景颜色和显示剪贴板中的文本文件内容
- CSS实现文本显示部分内容,多余文本显示省略号
- 通过viewSwitch实现加载进度条到内容显示的转场处理
- shell脚本中echo显示内容带颜色的实现方法
- Android UI 之居中绘制文本内容的正确方法——实现自定义一个TextView
- 1, 编写程序,当用户在文本框中输入内容之后,单机不同的按钮,能够把文半框中的内容粘贴到文本区中。“重置”按钮实现将文本框和文本区中的内容清空。界面上的文本区只能显示内容,不能让用户输入文本。运行结果
- Android UI 之居中绘制文本内容的正确方法——实现自定义一个TextView