Shell脚本 - cut、sort、paste

2023-05-16

1、cut:用来提取文件的片段

-d 后面指定分隔的符号

-f 指定显示第几列

-c 后面跟显示的字符1-n,character

-b 后面根据显示的字节,byte

kdvmt@kdvmt:temp$ cat 2.txt | cut -b 1-6
hello 
name y
leaf c
kdvmt@kdvmt:temp$ cat 2.txt | cut -c 1-5
hello
name 
leaf
kdvmt@kdvmt:temp$ cat 2.txt 
hello dog, hello cat
name you duplictae
leaf cup telephone
#根据空格进行分割
kdvmt@kdvmt:temp$ cat 2.txt | cut -d ' ' -f 1
hello
name
leaf
#根据逗号进行分割
kdvmt@kdvmt:temp$ cat 2.txt | cut -d ',' -f 1
hello dog
name you duplictae
leaf cup telephone
kdvmt@kdvmt:temp$ cat 2.txt | cut -d ',' -f 2
 hello cat
name you duplictae
leaf cup telephone

2、sort 用于对文本进行排序,默认是升序排列

-r:reverse 降序排列

-c:count 列出某一行出现的次数

kdvmt@kdvmt:temp$ sort 2.txt
hello dog, hello cat
leaf cup telephone
name you duplictae
kdvmt@kdvmt:temp$ sort -r 2.txt 
name you duplictae
leaf cup telephone
hello dog, hello cat

3、paste 对多文本进行合并,行合并

用-d指定分隔符,默认是tab

kdvmt@kdvmt:temp$ cat 1.txt 
hello
good
town
kdvmt@kdvmt:temp$ cat 2.txt 
world
morning
down
kdvmt@kdvmt:temp$ paste 1.txt 2.txt > 3.txt
kdvmt@kdvmt:temp$ cat 3.txt 
hello	world
good	morning
town	down
kdvmt@kdvmt:temp$ paste 1.txt 2.txt -d ':' > 3.txt
kdvmt@kdvmt:temp$ cat 3.txt 
hello:world
good:morning
town:down

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Shell脚本 - cut、sort、paste 的相关文章

随机推荐

  • 【玖哥乱弹】编程语言间的斗争

    在初级程序员阶段 xff0c 每个人都不可避免遇到选择编程语言和职业方向的难题 我挑选了几个常见的编程语言 xff0c 分析了优缺点和职业方向 xff0c 以供想当程序员的人参考 C C 43 43 一句话概括 xff1a 大多数中国程序员
  • 【玖哥乱弹】成功的IT人士这样转型AI

    AlphaGo在与围棋世界冠军的对弈大获全胜 xff0c 不但让我们领略到了AI的巨大潜力 xff0c 还把AI推上了新的浪潮之巅 作为一个从即将过去的移动互联网时代走来的Android工程师 xff0c 我深深感受到自己成了传统行业 xf
  • 【玖哥乱弹】程序员如何成为别人的男朋友

    这个世界上程序员数量很多 xff0c 有女朋友的程序员在其中的比例却很少 究其原因 xff0c 不外乎大多数程序员根本不知道怎么才能成为别人的男朋友 成为别人的男朋友对于富二代和拆迁户很容易 xff0c 而对于程序员却很难 xff0c 潘驴
  • Linux库函数之opendir/closedir/readdir

    在Linux环境下 xff0c 有时候需要编写一些实用的工具 xff0c 比如检索功能 xff0c 最近在做病毒查杀应用开发 xff0c 涉及到批量扫描指定目录下文件 xff0c 因为要测试大量病毒文件 xff0c 该部分功能又是要通过AP
  • 编译ROS包出现错误 提示:invoking "make cmake_check_build_system" failed

    问题原因 xff1a 不同包里不允许有重名的节点 解决方案 xff1a 编辑重复的package文件夹里的CMakeLists txt文件 xff0c 对涉及到节点名称的代码进行修改 调试过程 xff1a 逐行分析问题代码 xff0c 问题
  • Centos7.X添加本地至Docker用户组

    根据上篇文章 Centos7 X通过rpm包安装Docker 安装好Docker之后 xff0c 发现必须使用sudo提权的方式或者直接使用root方式才能操作docker xff0c 实际上我们平常登录都是自己的账户 xff0c 这样操作
  • pytorch填坑:RuntimeError: cudnn RNN backward can only be called in training mode

    运行pytorch时 xff0c 训练很正常 xff0c 但是如果切换到eval 模式之后再继续训练 xff0c 发现报错 xff1a RuntimeError cudnn RNN backward can only be called i
  • Linux Mint 18.2安装VMware Workstation Pro 12

    VMware Workstation xff08 中文名 威睿工作站 xff09 是一款功能强大的桌面虚拟计算机软件 xff0c 提供用户可在单一的桌面上同时运行不同的操作系统 xff0c 和进行开发 测试 部署新的应用程序的最佳解决方案
  • ubuntu 使用nginx和gunicorn 部署服务

    1 安装gunicorn pip install gunicorn 2 创建下列名为web py的文件 xff1a from flask import Flask app 61 Flask name 64 app route 39 39 d
  • unable to execute ':/usr/local/cuda/bin/nvcc': No such file or directory

    仔细看下面的错误 xff1a unable to execute 39 usr local cuda bin nvcc 39 No such file or directory 是多了一个冒号 解决方式 xff1a vi bashrc 将
  • ubuntu系统设置ssh连接端口

    1 sudo vim etc ssh sshd config 将其中的 Port 22行取消注释 xff0c 并且将22换成自己想要的端口 xff0c 例如5677等 2 重启ssh服务 systemctl restart sshd net
  • anaconda 环境查找虚拟环境

    1 查找虚拟环境 conda info envs 会出现如下结果 2 选择虚拟环境 source activate tensorflow p36 3 退出虚拟环境 source deactivate 4 安装librosa conda in
  • python logging.info在终端没输出

    问题描述 在pyhton脚本中logging info 34 hello world 34 希望输出 39 hello world 39 但是在终端没有输出 解决方法 在文件开始的地方添加以下内容 span class pln style
  • ImportError: libSM.so.6: cannot open shared object file: No such file or directory解决

    运行如下命令即可解决 span class pln style margin 0px padding 0px border 0px font style inherit font weight inherit font size 6 lin
  • linux 查看版本信息

    1 uname xff0d a xff08 Linux查看版本当前操作系统内核信息 xff09 Linux ml 4 4 0 109 generic 132 Ubuntu SMP Tue Jan 9 19 52 39 UTC 2018 x8
  • 你真的了解串口吗(示波器串口波形分析)

    串口是最常用的外设了 xff0c 串口基本都是单片机的标配 串口通信只需要3条线组成 xff0c 分别为RX TX GND 下面将重点分析串口数据帧组成 一 串口通信帧 串口通信帧数据如此 xff0c 每帧由空闲位 起始位 数据位 校验位
  • C++——类和对象(4)

    作者 xff1a 几冬雪来 时间 xff1a 2023年5月6日 内容 xff1a C 43 43 类和对象内容讲解 目录 前言 xff1a 1 运算符重载 xff08 续 xff09 xff1a 2 赋值重载 xff1a 结尾 xff1a
  • Shell脚本-NF、FS(OFS)、RS(ORS)、NR(FNR)

    1 NF xff1a number of fileds xff08 字段 域的个数 xff09 整数 NF xff1a 取最后一列的字符串 xff0c 等同于 1 2 xff0c NF 1 NF等等 来看个例子吧 kdvmt 64 kdvm
  • 七月历程

    六月底老师通知让我提前返校 xff0c 去长春自我隔离一段时间 xff0c 这几天一直在收拾东西 空余时间没用来学习 xff0c 不过倒是上 steam 上买了个游戏 QAQ 2020 是个多灾多难的年份 澳洲火灾 xff0c 东非蝗虫肆虐
  • Shell脚本 - cut、sort、paste

    1 cut xff1a 用来提取文件的片段 d 后面指定分隔的符号 f 指定显示第几列 c 后面跟显示的字符1 n xff0c character b 后面根据显示的字节 xff0c byte kdvmt 64 kdvmt temp cat