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

所属分类: 脚本专栏 / DOS/BAT 阅读数: 477
收藏 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.
更多精彩内容其他人还在看

sxs.exe的查杀bat代码

在每个盘根目录下自动生成sxs.exe,autorun.inf文件,有的还在windows\system32下生成SVOHOST.exe 或 sxs.exe ,文件属性为隐含属性。自动禁用杀毒软件,这篇文章主要是介绍批处理查杀病毒的一些技巧,需要的朋友可以参考下
收藏 0 赞 0 分享

判断分区格式的bat代码

判断分区格式的bat代码,需要的朋友可以参考下
收藏 0 赞 0 分享

Bat脚本处理ftp超强案例分析

公司有几百台windows服务器,每次程序更新,如果是一台台拷数据,只怕安排十个人,一天都不一定做得完,所以就必须研究个全自动更新方案来,于是就想到了FTP,做个主FTP站,在几百台客户机上启动BAT脚本,每30秒检测一次,如果主站有更新程序,就自动下载更新
收藏 0 赞 0 分享

cmd命令行大全 dos命令 cmd命令整理

cmd命令行大全 dos命令 cmd命令,方便学习cmd的朋友,大家可以通过Ctrl+F查找定位
收藏 0 赞 0 分享

利用 bat 文件制作 HOSTS 快速切换器

在平时每天需要切换好几次 HOSTS 文件,那有什么办法可以简化这个操作
收藏 0 赞 0 分享

批量安装windows补丁的批处理脚本

其实就是通过for命令实现批量安装,大家只要熟练使用for命令就可以节约很多时间
收藏 0 赞 0 分享

在CMD下读取服务器终端的端口的代码

这个批处理可以用来查看服务器远程终端的端口,不过是16进制的
收藏 0 赞 0 分享

Windows批量添加防火墙例外端口的批处理代码

有时候我们需要添加很多端口到防火墙例外,如果一个一个手工添加很累,那么就可以利用下面的方法
收藏 0 赞 0 分享

bat定时自动关机,bat自动结束任务关闭程序,dos自动结束程序后关机

bat定时自动关机,bat自动结束任务关闭程序,dos自动结束程序后关机的命令介绍
收藏 0 赞 0 分享

复制文件到c盘windows文件夹下的system32的批处理写法

三个文件复制到c盘windows文件夹下的system32文件夹 批处理怎么写?本文提供解决方法,需要的朋友可以了解下
收藏 0 赞 0 分享
查看更多