批处理实现文本内容居中显示的代码

所属分类: 脚本专栏 / DOS/BAT 阅读数: 461
收藏 0 赞 0 分享
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.

Batcher:

sed -e :a -e "s/^.\{1,77\}$/ & /;ta" a.txt

sed.exe
http://xiazai.jb51.net/201010/tools/sed_jb51.rar 

batman:思路说明:
以下代码是充分findstr命令的示例,使用findstr /n来取得行号同时兼容空行,
并将行号进行变量赋值;使用findstr /o来取得第行的字符偏移量,但要通过
上、下行的字符偏移差,因为字符偏移值是类计递加的,同时每行回车增加
两个字符偏移,所以不可避免要对最后一行强加回车,在不破坏原文件的情
况下只好生成临时文件;利用findstr /o能够一次性获得文本所有行的字符偏
移量也就是字符总数,效率和逐字符判断相比肯定是高得多了。
---------------------------------
复制代码 代码如下:

@echo off
copy /y 1.txt 2.txt>nul
echo.>>2.txt&echo end>>2.txt
for /f "tokens=1,2* delims=: " %%i in ('findstr /n /o .* 2.txt') do (
set "_%%i=%%j"&set ".%%i=%%k"
  if %%i geq 2 call :lp %%i
)
del /q 2.txt&pause>nul&goto :eof
:lp
set /a n=%1-1
set /a num=_%1-_%n%-2
set /a kl=(80-num)/2
for /l %%i in (1,1,%kl%) do set /p= <NUL
call,set /p=%%.%n%%%<NUL&ECHO.
更多精彩内容其他人还在看

mshta命令用法示例

这篇文章主要介绍了mshta命令用法示例 ,需要的朋友可以参考下
收藏 0 赞 0 分享

使用BAT批处理执行sql语句的代码

有时候需要执行一些Sql语句时,不想开企业管理器,或者是发给客户执行但那边又不懂代码,这时就可以用下面方法
收藏 0 赞 0 分享

批处理的图形界面实现方法小结

其实所谓的图形界面就是通过bat通过调用mshta来实现的一些对话框效果,这里特整理下, 方便需要的朋友
收藏 0 赞 0 分享

批处理中的echo命令图文详解

这篇文章主要介绍了批处理中的echo命令图文详解,里面都附有详细的图片执行效果,非常不错需要的朋友可以参考下
收藏 0 赞 0 分享

批处理中常用命令介绍(Echo、rem、goto、call、pause、if、for)

这篇文章主要介绍了批处理中常用命令介绍,包括Echo、rem、goto、call、pause、if、for,学习bat必备的啊
收藏 0 赞 0 分享

改变cmd命令提示符颜色的3个小技巧

这篇文章主要介绍了改变cmd命令提示符颜色的3个小技巧,推荐使用第三个技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

使用BAT批处理在RAR压缩文件中批量添加文件的方法

这篇文章主要介绍了使用BAT批处理在RAR压缩文件中批量添加文件的方法,可以用在很多地方,例如做下载加的朋友,想要加个网站快捷方式在以前压好的压缩文件中等,需要的朋友可以参考下
收藏 0 赞 0 分享

bat 传递超过10个参数的情况

批处理文件中可引用的参数为%0~%9, %0是指批处理文件的本身,也可以说是一个外部命令;%1~%9是批处理参数,也称形参;而替换形参的实参若超过了批处理文件中所规定数值(9个)且想在批处理文件中应用这些实参的话,shift命令可以帮你实现
收藏 0 赞 0 分享

BAT 参数去引号(各种去引号的奇葩方式)

这篇文章主要介绍了BAT 参数去引号,各种去引号的奇葩方式,需要的朋友可以参考下
收藏 0 赞 0 分享

使用批处理命令设置windows系统的ip地址和dns附图

这篇文章主要介绍了如何使用批处理命令设置windows系统的ip地址和dns,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多