0032. shell命令--paste

目录

32. shell命令--paste

功能说明

语法格式

选项说明

实践操作

注意事项


32. shell命令--paste

功能说明

        paste 是一个在 Unix 和 Linux 系统中用于合并文件行内容的命令。它的主要用途是将多个文件的行合并在一起,默认情况下,它会将将多个文件按照列队列进行合并,并使用制表符(\t)作为分隔符。如需先将内容合并成一行,再以行粘贴的方式合并,可以用-s参数搞定

语法格式

SYNOPSIS
       paste [OPTION]... [FILE]...

选项说明

  • -d, --delimiters=LIST:使用 LIST 中的字符作为分隔符,而不是制表符。例如,-d',' 将使用逗号作为分隔符。
  • -s, --serial:将每个文件的行串行化,而不是并行合并。这会将每个文件的所有行合并为一个长行。
  • --help:显示帮助信息。
  • --version:显示版本信息。

实践操作

0. 环境准备
mkdir -p /test/paste
cd /test/paste

cat >file1.txt <<'eof'
1.aaa
1.bbb
1.ccc
1.ddd
1.eee
eof

cat >file2.txt <<'eof'
2.AAA
2.BBB
2.CCC
2.DDD
eof

head -v file*

1. 默认对两个文件进行合并
cat file*    #使用cat也能合并,只是上下合并
paste file1.txt file2.txt    #并列合并,默认使用制表符(\t)作为分隔符

2. 设置合并后的分隔符,然后进行合并
paste -d"-->" file1.txt file2.txt    #设置 --> 为分隔符,但是只显示-
paste -d'|' file1.txt file2.txt
paste -d'\' file1.txt file2.txt
paste -d'\\' file1.txt file2.txt

3. 设置每个文件内容为一行,再进行合并
paste -s file1.txt file2.txt
paste -s file1.txt file2.txt >newfile.txt
cat newfile.txt

注意事项

  • 如果文件行数不同,paste 会按照最短的文件长度来合并。例如,如果 file1.txt 有 3 行,而 file2.txt 只有 2 行,那么 paste 只会合并前两行。
  • 如果文件不存在或无法读取,paste 会显示错误消息。
  • paste 命令不会修改原始文件,它只会输出合并后的内容到标准输出(通常是终端或重定向的文件)。
sudo apt update sudo apt install -y mongodb-org Hit:1 http://mirrors.tencentyun.com/ubuntu focal InRelease Hit:2 http://mirrors.tencentyun.com/ubuntu focal-updates InRelease Hit:3 http://mirrors.tencentyun.com/ubuntu focal-backports InRelease Hit:4 http://mirrors.tencentyun.com/ubuntu focal-security InRelease Hit:5 https://download.docker.com/linux/ubuntu focal InRelease Hit:6 http://ppa.launchpad.net/git-core/ppa/ubuntu focal InRelease Get:7 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0 InRelease [3,005 B] Get:8 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 Packages [53.2 kB] Fetched 56.2 kB in 2s (34.0 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libboost-filesystem1.71.0 libboost-iostreams1.71.0 libboost-program-options1.71.0 libgoogle-perftools4 libpcap0.8 libsnappy1v5 libtcmalloc-minimal4 libunwind8 libyaml-cpp0.6 mongo-tools mongodb-server-core Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: mongodb-database-tools mongodb-mongosh mongodb-org-database mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools The following packages will be REMOVED: mongodb mongodb-clients mongodb-server The following NEW packages will be installed: mongodb-database-tools mongodb-mongosh mongodb-org mongodb-org-database mongodb-org-database-tools-extra mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools 0 upgraded, 9 newly installed, 3 to remove and 0 not upgraded. Need to get 186 MB of archives. After this operation, 600 MB of additional disk space will be used. Get:1 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-database-tools amd64 100.13.0 [58.9 MB] Get:2 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-mongosh amd64 2.5.9 [57.9 MB] Get:3 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-org-shell amd64 8.0.15 [3,088 B] Get:4 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-org-server amd64 8.0.15 [39.7 MB] Get:5 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-org-mongos amd64 8.0.15 [29.8 MB] Get:6 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-org-database-tools-extra amd64 8.0.15 [7,756 B] Get:7 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-org-database amd64 8.0.15 [3,544 B] Get:8 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-org-tools amd64 8.0.15 [2,896 B] Get:9 https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/8.0/multiverse amd64 mongodb-org amd64 8.0.15 [2,936 B] Fetched 186 MB in 4s (42.4 MB/s) debconf: delaying package configuration, since apt-utils is not installed (Reading database ... 38109 files and directories currently installed.) Removing mongodb (1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3) ... Removing mongodb-server (1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3) ... invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of stop. Removing mongodb-clients (1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3) ... Selecting previously unselected package mongodb-database-tools. (Reading database ... 38091 files and directories currently installed.) Preparing to unpack .../0-mongodb-database-tools_100.13.0_amd64.deb ... Unpacking mongodb-database-tools (100.13.0) ... dpkg: error processing archive /tmp/apt-dpkg-install-Q6AJHa/0-mongodb-database-tools_100.13.0_amd64.deb (--unpack): trying to overwrite '/usr/bin/bsondump', which is also in package mongo-tools 3.6.3-0ubuntu1 dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) Selecting previously unselected package mongodb-mongosh. Preparing to unpack .../1-mongodb-mongosh_2.5.9_amd64.deb ... Unpacking mongodb-mongosh (2.5.9) ... Selecting previously unselected package mongodb-org-shell. Preparing to unpack .../2-mongodb-org-shell_8.0.15_amd64.deb ... Unpacking mongodb-org-shell (8.0.15) ... Selecting previously unselected package mongodb-org-server. Preparing to unpack .../3-mongodb-org-server_8.0.15_amd64.deb ... Unpacking mongodb-org-server (8.0.15) ... dpkg: error processing archive /tmp/apt-dpkg-install-Q6AJHa/3-mongodb-org-server_8.0.15_amd64.deb (--unpack): trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3 dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) Selecting previously unselected package mongodb-org-mongos. Preparing to unpack .../4-mongodb-org-mongos_8.0.15_amd64.deb ... Unpacking mongodb-org-mongos (8.0.15) ... dpkg: error processing archive /tmp/apt-dpkg-install-Q6AJHa/4-mongodb-org-mongos_8.0.15_amd64.deb (--unpack): trying to overwrite '/usr/bin/mongos', which is also in package mongodb-server-core 1:3.6.9+really3.6.8+90~g8e540c0b6d-0ubuntu5.3 dpkg-deb: error: paste subprocess was killed by signal (Broken pipe) Selecting previously unselected package mongodb-org-database-tools-extra. Preparing to unpack .../5-mongodb-org-database-tools-extra_8.0.15_amd64.deb ... Unpacking mongodb-org-database-tools-extra (8.0.15) ... Selecting previously unselected package mongodb-org-database. Preparing to unpack .../6-mongodb-org-database_8.0.15_amd64.deb ... Unpacking mongodb-org-database (8.0.15) ... Selecting previously unselected package mongodb-org-tools. Preparing to unpack .../7-mongodb-org-tools_8.0.15_amd64.deb ... Unpacking mongodb-org-tools (8.0.15) ... Selecting previously unselected package mongodb-org. Preparing to unpack .../8-mongodb-org_8.0.15_amd64.deb ... Unpacking mongodb-org (8.0.15) ... Errors were encountered while processing: /tmp/apt-dpkg-install-Q6AJHa/0-mongodb-database-tools_100.13.0_amd64.deb /tmp/apt-dpkg-install-Q6AJHa/3-mongodb-org-server_8.0.15_amd64.deb /tmp/apt-dpkg-install-Q6AJHa/4-mongodb-org-mongos_8.0.15_amd64.deb E: Sub-process /usr/bin/dpkg returned an error code (1)
最新发布
11-13
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MineGi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值