转载:http://blog.csdn.net/vicant/article/details/2317721

有时候需要给文本加上行号,用UNIX的cat命令可以进行这项工作。

cat命令的用法如下:
 NAME
          cat - concatenate, copy, and print files
 SYNOPSIS
          cat [-benrstuv] file ...
Options
      cat recognizes the following options:
           -b   Omit line numbers from blank lines when -n option is
                specified. If this option is specified, the -n option is
                automatically selected.

-e   Print a $ character at the end of each line (prior to the
                new-line).  If this option is specified, the -v option is
                automatically selected.

-n   Display output lines preceded by line numbers, numbered
                sequentially from 1.

-r   Replace multiple consecutive empty lines with one empty
                line, so that there is never more than one empty line
                between lines containing characters.

-s   Silent option.  cat suppresses error messages about non-
                existent files, identical input and output, and write
                errors.  Normally, input and output files cannot have
                identical names unless the file is a special file.

-t   Print each tab character as ^I and form feed character as
                ^L.  If this option is specified, the -v option is
                automatically selected.

-u   Do not buffer output (handle character-by-character).
                Normally, output is buffered.

cat -n 可以加上行号,cat -b 也可以加上行号,但会忽略空行。
如下命令可以为file1加上空行后,输入为file2(空行也加上行号):

cat -n file1 > file2

如下命令可以为file1加上空行后,输入为file2(空行不加行号):

cat -b file1 > file2

用UNIX的cat命令用于给文本加行号 (转载)的更多相关文章

  1. cat命令详解

    命令cat cat 命令用于连接文件并打印到标准输出设备上 语法格式: cat [-AbeEnstTuv] [--help] [--version] fileName 参数说明: -n 或 --num ...

  2. linux命令详解:cat命令

    转:http://www.cnblogs.com/lwgdream/archive/2013/11/06/3409802.html 前言 cat命令用于读取文本文件,并且能够显示行号.特殊字符等. 使 ...

  3. linux学习(三)输入输出重定向和管道功能、cat命令、more命令

    目录 输入输出重定向 输出重定向 管道功能 cat命令 more命令 @(输入输出重定向和管道功能) 输入输出重定向 输入重定向可以让用户将某个文件作为输入设备,输出重定向可以把某个文件作为输出设备, ...

  4. linux命令之------Cat命令

    Cat命令 作用:cat命令用于连接文件并打印,查看文件内容: -n或--number:由1开始对所有输出的行数编号: -b或--number-nonblank:和-n相似,只不过对于空白行不做编号: ...

  5. Linux cat命令使用方法

    今天小编为大家带来cat的使用方法命令:catcat 命令用于连接文件并打印到标准输出设备上.使用权限所有使用者 语法格式cat [-AbeEnstTuv] [–help] [–version] fi ...

  6. 每天一个Linux常用命令 cat命令

    在Linux系统中,cat命令是一个文本输出命令,通常用来查看某个文档的内容.它有如下三个功能: 1.一次性显示整个文件 如:查看/etc/initab文件,可以使用命令:cat/etc/initta ...

  7. 【Linux常见命令】cat命令

    cat - concatenate files and print on the standard output cat 命令用于连接文件并打印到标准输出设备上. 用法: 1. cat file 查看 ...

  8. cut命令用于按“列”提取文本字符,格式为“cut [参数] 文本”

    8.cut命令 cut命令用于按"列"提取文本字符,格式为"cut [参数] 文本". 在Linux系统中,如何准确地提取出最想要的数据,这也是我们应该重点学习 ...

  9. 28个Unix/Linux的命令行神器_转

    28个Unix/Linux的命令行神器 下面是Kristóf Kovács收集的28个Unix/Linux下的28个命令行下的工具,有一些是大家熟悉的,有一些是非常有用的,有一些是不为人知的.这些工具 ...

随机推荐

  1. java HashMap的使用

    java HashMap的使用 import java.util.HashMap; import java.util.Iterator; public class WpsklHashMap { pub ...

  2. HDU 3966

    树链剖分 练模板: 用的 是HH的线段树 虽然之前是我不用的摸板 修改区间 求点值: CODE: #pragma comment(linker,"/STACK:1024000000,1024 ...

  3. Docker安装redis操作命令

    最近学习了redis,那么今天我们来学习以下在Docker上安装我们的redis,并查看有关redis的一系列命令 查找redis docker search redis 拉取redis docker ...

  4. curl post请求方式

    curl -l -H "application/x-www-form-urlencoded; charset=UTF-8" -X POST -d "query=SELEC ...

  5. openstack swift memcached

    如果生成的token总变,说明没有启动memcached: swift@vincent-virtual-machine /usr/bin $ memcached -p 11211 -m 64m -d ...

  6. 分布式 OLTP 数据库

    PingCAP招聘职位-拉勾网-最专业的互联网招聘平台 分布式 OLTP 数据库

  7. ssh 执行多条命令包含awk的用法

    格式:ssh user@ip command 单条命令:ssh user@ip command1 多条命令:ssh user@ip "command1;command2" 不加双引 ...

  8. 【转】ubuntu 下安装mongodb php 拓展的方法

    按照上面的方法安装成功之后,写一个 mongodb 的php测试脚本,用来测试是否可以 正确连接上mongodb ,并查询结果. 参考:http://php.net/manual/en/class.m ...

  9. freemarker 模板

    1 整体结构 模板(FTL 编程)是由例如以下部分混合而成的: Text 文本:文本会照着原样来输出. Interpolation 插值:这部分的输出会被计算的值来替换.插值由${和}所分隔(或者#{ ...

  10. oracle 正则查询json返回报文中某个字段的值

    接口返回报文为json 格式,如下: {"body":{"businessinfo":{"c1rate":"25.00" ...