转载: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. php之ThinkPHP的memcached类的修改

    php之ThinkPHP的memcached类的修改 在Think\Cache\Driver\Memcached.class.php中,增加方法获取错误信息的方法,方便调试, public funct ...

  2. 352. Data Stream as Disjoint Interval

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  3. 推荐10+必备的 WordPress 常用插件

    众多的WordPress插件,使得WordPress的功能得到了较大的扩展,但是也正是由于过多的插件,导致我们很难选择所需的插件.今天,倡萌就根据自己的经验,给WordPress新手推荐一些常用的插件 ...

  4. 最近公共祖先(Least Common Ancestors)

    题意: 给定一棵有根树T,给出若干个查询lca(u, v)(通常查询数量较大),每次求树T中两个顶点u和v的最近公共祖先,即找一个节点,同时是u和v的祖先,并且深度尽可能大(尽可能远离树根).通常有以 ...

  5. HDU 5667 Sequence

    指数有递推式,可以通过矩阵快速幂来求解.再用下面这公式快速幂取模即可. (C是素数) #include<cstdio> #include<cstring> #include&l ...

  6. Java实验——输出二维数组连续二维子数组的最大和

    该算法思路,根据我博客里面一维子数组求和的思路,可以用一个新的二维数组对该二维区域的数组进行求和,例如新的二维数组的第5个位置,就代表从1到5斜对角线的块状区域的和,即1,2,4,5这4个数的和,x个 ...

  7. 转 asterisk app命令中文翻译

    常规指令 Authenticate:鉴别用户 VMAuthenticate:根据“voicemail.conf”鉴别用户 Curl:接受外接URLs的修复.支持POSTing DUNDiLookup: ...

  8. vs npm设置淘宝npm

    VS2017自带的npm会去国外的镜像下载文件, 奇慢无比, 还是马云家淘宝的镜像适合国内用户. 淘宝npm镜像地址:  https://registry.npm.taobao.org VS中使用淘宝 ...

  9. linux安装mail服务使用外部MTA发送邮件

    阉割版的linux没有mail命令,也没有/etc/mail.rc文件 需要安装mail服务 yum install mailx.x86_64 几个概念:MUA.MTA.MDA 邮件用户代理(MUA, ...

  10. Deepin-安装(读写文件)权限

    在安装NODE管理模块N时,遇到了权限问题 1.给予程序读写权限(仅限文件夹) 查看权限:ls -l 或 ls 添加权限: 示例:chmod +rw xx 实例:chmod +rw node 关于权限 ...