转载: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. Codeforces 549C The Game Of Parity【博弈】

    C语言纠错大赛的一道题,正好拿来补博弈~~ 给的代码写的略奇葩..不过还是直接在上面改了.. 题目链接: http://codeforces.com/problemset/problem/549/C ...

  2. Toy Storage--POJ2398(计算几何)

    http://poj.org/problem?id=2398 这道题和上一道TOYS是一样的   就是输出不一样  还有就是这个给的是乱序  你要先对挡板排序 #include <iostrea ...

  3. 2017-10-04-afternoon

    注意完全平方数统计时的特判 #include <cstdio> inline void read(int &x) { x=; register char ch=getchar(); ...

  4. maven之基础

    一.配置maven的环境 下载地址:http://maven.apache.org/download.cgi(window下载(Binary zip)的) 将maven解压,然后配置环境变量打开: 计 ...

  5. Callable线程

    写一个Callable线程 import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; im ...

  6. [RxJS] Chain RxJS Operators Together with a Custom `pipe` Function using Array.reduce

    Instead of writing complex operators, it's usually best to write simple, single-purpose operators th ...

  7. C#中list比数组效率低多少

    对于List,即长度不确定的数组而言,十万笔数据*12倍,就是120万笔数据,只需要93ms左右   换成了二维数组,效果也是差不多,78ms,可见list的效率只比double差一点点  

  8. HDU 5301 Buildings(2015多校第二场)

    Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  9. Dropbox电面面经

    他家电面有2轮,等待onsite.. . 电面1: 国人MM面的.这点感觉非常难得. 统计近期5分钟的点击量,实现hit和getHit两个函数.这题是他家高频题,我用deque实现的,hit的均摊时间 ...

  10. oracle获取字符串长度函数length()和lengthb()

    oracle获取字符串长度函数length()和lengthb()   lengthb(string)计算string所占的字节长度:返回字符串的长度,单位是字节 length(string)计算st ...