使用终端(或命令行管理程序)将文件的一部分复制/粘贴到另一个文件中 [英] Copy/Paste part of a file into another file using Terminal (or Shell)

查看:329
本文介绍了使用终端(或命令行管理程序)将文件的一部分复制/粘贴到另一个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将.txt文件的一部分从行号n复制到行号n + y(比如说1000到1000000)。

I am trying to copy part of a .txt file from the line number n to the line number n+y (let's say 1000 to 1000000).

我尝试过与运营商和 sed 合作,但失败了。这是我尝试的命令:

I tried with operators and sed, and it failed. Here's the command I tried:

sed -n "1000, 1000000p" path/first/file > path/second/file


推荐答案

如果知道多少行在源文件(wc -l)中,可以执行此操作..假设12000行,并且您希望新文件中包含2000-7000行(总共5000行)。

if you know how many lines are in your source file (wc -l) you can do this .. assume 12000 lines and you want lines 2000 - 7000 in your new file (total of 5000 lines).

cat myfile |尾巴-10000 | head -5000> newfile

cat myfile | tail -10000 | head -5000 > newfile

读取最后一万行,然后从中读取第一个5k行。

Read the last 10k lines, then read the 1st 5k lines from that.

这篇关于使用终端(或命令行管理程序)将文件的一部分复制/粘贴到另一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆