cat & 文件结束符
语法:
连接显示
选项:
-n,显示行号。
-v,显示不可见打印符。
-E,显示“行结束符”($)。
显示行号
$ cat -n /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults
LABEL=/boot /boot ext3 defaults
tmpfs /dev/shm tmpfs defaults
devpts /dev/pts devpts gid=,mode=
sysfs /sys sysfs defaults
proc /proc proc defaults
/dev/VolGroup00/LogVol01 swap swap defaults
打印行末结束符
$ cat -E /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults $
LABEL=/boot /boot ext3 defaults $
tmpfs /dev/shm tmpfs defaults $
devpts /dev/pts devpts gid=,mode= $
sysfs /sys sysfs defaults $
proc /proc proc defaults $
/dev/VolGroup00/LogVol01 swap swap defaults $
直接输入命令,就会进入交互模式。直到cat接到一个“文件结束符”时停止交互。
$ cat
hello
hello
are you busy?
are you busy?
$
重写程序(case语句的第一个例子“找工作时联系人信息”),使用“文件结束符”,格式化显示交互信息:
#!/bin/bash cat << EOF
Recruitment Announcement
Are you ready to apply for any job?
accounting
cashier
secretary
Please enter a number to select the corresponding positions.
EOF echo -n "Choice: "
read NUM
case $NUM in
)
printf "call mr wang. number is 1124\n"
;;
)
printf "call miss li. number is 1233.\n"
;;
)
printf "call miss ji. number is 1367.\n"
;;
*)
printf "If you want to make a lot of money, to be a seller. call 1498.\n"
;;
esac
打印程序的提示信息:
display_help () {
cat << EOF
Usage: findTom [OPTION]
View the tomcat information.
View the home directory of the tomcat program running on the system, and
the project path.
Mandatory arguments to long option are mandatory for short options too.
-r, --read
view the previously running tomcat information.
-v, --version
view the version
--clear
when the number of row is greater than , then clean-up, and leaving lines.
-h, --help
display this help and exit
E-mail bug reports to: <@qq.com>
EOF
}
执行上边的代码,效果如下:
$ ./cat.sh
Recruitment Announcement
Are you ready to apply for any job?
accounting
cashier
secretary
Please enter a number to select the corresponding positions.
Choice:
从程序的输出看出,脚本里的文本格式原样在交互界面显示了。
文件结束符:
Linux: CTRL + d
Windows: CTRL + z
cat & 文件结束符的更多相关文章
- linux下文件结束符
linux下文件结束符,我试过了所有的linux,发现其文件的结束符都是以0a即LF结束的,这个是操作系统规定的,windows下是\r\n符结束,希望可以帮助大家. -------------转:来 ...
- 文件结束符和C\C++读取文件方式
http://www.cnblogs.com/cvbnm/articles/2003056.html 约定编译器为 gcc2/x86: 所以 char, unsigned char 为 8 位, in ...
- Windows环境下C++中关于文件结束符的问题
参考资料:http://www.cnblogs.com/day-dayup/p/3572374.html 一.前言 在不同的OS环境下,程序中对应的文件结束符有所不一样,根据<C++ Prime ...
- 关于windows下的文件结束符
在<c++ primer>中有说,在windows中文件结束符为:ctrl+z,在Linux中为:ctrl+D. 但是在while(cin>>s)的语句运行中,需要两次的^Z, ...
- linux 下vim文件乱码 cat文件正常处理方法
linux 下vim文件乱码 cat文件正常处理方法 服务器支持中文字符集,cat和其他查看文件命令现在正常,vim还是出现了中文乱码问题, 1.查看文件编码格式 vim 文件 :set fileen ...
- 关于文件结束符EOF
EOF 是 End Of File 的缩写. 在 C 语言中,它是在标准库中定义的一个宏. 人们经常误认为 EOF 是从文件中读取的一个字符(牢记).其实,EOF 不是一个字符,它被定义为是 int ...
- linux cat 文件操作
简略版: cat主要有三大功能:1.一次显示整个文件.$ cat filename2.从键盘创建一个文件.$ cat > filename 只能创建新文件,不能编辑已有文件.3.将几个文 ...
- linux cat 文件编码
test.log是utf-16的编码 cat test.log会报错 但是我们可以cat的时候指定编码格式 iconv -f 文件编码 -t 终端编码 input.log iconv -f utf-1 ...
- Linux cat文件正常,vim文件乱码
cat: vim: 1.临时解决 vim 文件后,命令模式下执行: :set encoding=utf-8 2.永久解决 vi 配置文件路径:/etc/virc vim 配置文件路径:/etc/ ...
随机推荐
- pandas初识
pandas初识 1.生成DataFrame型的数据 import pandas as pd import numpy as np dates = pd.date_range('20130101',p ...
- hadoop HA分布式集群搭建
概述 hadoop2中NameNode可以有多个(目前只支持2个).每一个都有相同的职能.一个是active状态的,一个是standby状态的.当集群运行时,只有active状态的NameNode是正 ...
- SynergyS7G2RTC时钟模块的使用
RTC功能描述 RTC时钟模块是Synergy芯片的一个时间外设,主要用于日期时间的存储和控制,有别于一般MCU中的Timer,RTC时钟有两种计时模式,日期模式和二进制计时模式,其中日期模式的时间可 ...
- 【java】之正则表达式摘要
构造 匹配 字符 x 字符 x \\ 反斜线字符 \0n 带有八进制值 0 的字符 n (0 <= n <= 7) \0nn 带有八进制值 0 的字符 nn (0 <= n < ...
- C# name scheme
1.For varibale.camel scheme.the first word lowercase the first letter,then other words capitalize th ...
- bzoj3491: PA2007 Subsets
Description 有一个集合U={1,2,…,n),要从中选择k个元素作为一个子集A.若a∈A,则要有a*X不属于A,x是一个给定的数.求可选方案对M取模后的值. 1< = N< = ...
- go get golang.org/x 包失败解决方法
由于墙的原因,国内使用 go get安装golang 官方包可能会失败 解决方法 方法1 [不需要FQ] Win10下相关配置: GOPATH : E:\go 安装记录: E:\>go get ...
- react-router 4.x
本次主要总结react中的路由的使用,实现让根组件根据用户访问的地址动态挂载不同的组件. 1,创建项目 首先使用命令 npx create-react-app react-router创建项目,然后n ...
- tcpdump命令(转载)
https://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html 简介 用简单的话来定义tcpdump,就是:dump the tra ...
- python输出缓冲区的问题
碰到的问题,一段代码,print在前,log的在后,查看日志中log的反而在前面.是python输出缓冲区的问题. python输出缓冲区要满 4k 才写入文件,除非禁用缓存或者强制输出或者程序结束. ...