BAT批处理之type命令

Type命令对一般文本文件(.txt)进行处理,对其他类型文件就不好用了。

基本语法 type [drive] [path] [filename],本命令是用于打开txt文档,并在cmd窗口显示txt中的内容。

实例一
type helloworld.txt

以下是源代码:

@echo off
echo the below content from helloworld:
echo.
type helloworld.txt
echo.
echo.
pause

执行后:

the below content from helloworld:

Stray birds of summer come to my window to sing and fly away.
And yellow leaves of autumn, which have no songs, flutter and fall
there with a sign.

Press any key to continue . . .

实例二
通过type命令合并两个txt文档。提前新建两个txt文档,一个是pen.txt内容是 “I have a pen,”,再新建一个apple.txt内容是“I have an apple”,最后我们合并的文件名叫PPAP.txt。

以下是源代码:

@echo off
echo pen.txt below:
type pen.txt
echo.
echo.
echo apple.txt below:
type apple.txt
echo.
type pen.txt apple.txt > PPAP.txt
echo.
type PPAP.txt
echo.
echo.
pause

执行后:

pen.txt below:
I have a pen,

apple.txt below:
I have an apple.

pen.txt



apple.txt



I have a pen,I have an apple.

Press any key to continue . . .

其实还有更多命名,推丸菌就不一 一运行了,仅把命令和介绍罗列如下:

type 文件名 | more    ::“type 文件名”是将内容一次性打印出来,加上“more”命令是分页打印,并且按任意键可以获得后续内容,很适合内容多的文件
type 文件名 | findstr [/i] 内容    ::该命令类似于查找命令,即查找“内容”并打印出来,其他的无关内容不会打印出来,/i表示是否区分大小写
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值