简体   繁体   English

使用终端(或Shell)将文件的一部分复制/粘贴到另一个文件中

[英]Copy/Paste part of a file into another file using Terminal (or Shell)

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). 我试图将.txt文件的一部分从行号n复制到行号n + y(假设1000到1000000)。

I tried with operators and sed , and it failed. 我试过运营商和sed ,但它失败了。 Here's the command I tried: 这是我试过的命令:

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

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). 如果您知道源文件(wc -l)中有多少行,则可以执行此操作。假设12000行,并且您希望新文件中的行2000 - 7000(总共5000行)。

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

Read the last 10k lines, then read the 1st 5k lines from that. 读取最后10k行,然后读取第1行5k行。

sed命令应该可以正常工作,用单引号替换双引号。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将文本从一个 Vim 文件复制/粘贴到另一个 shell 选项卡中的另一个 Vim 文件? - How can I copy/paste text from one Vim file to another Vim file in another shell tab? 使用 shell 脚本将特定单词从一个文件复制到另一个文件 - Copy specific word from a file to another file using shell script 如何使用Shell从文件中的一行复制值并将其粘贴到新文件中? - How to copy value from a line in a file and paste it into a new file using Shell? Shell脚本从目录复制并粘贴随机文件 - Shell Script copy and paste a random file from a directory 使用shell工具提取文件的一部分 - Using shell tools to extract part of a file 从目录复制文件并将其粘贴到 linux(ubuntu) 终端中的多个子目录? - Copy a file from a directory and paste it to multiple sub directories in linux(ubuntu) terminal? bash shell使用break将文件从一个位置复制到另一个位置并继续 - bash shell copy the file from one location to another using break and continue Shell 脚本将文件从一个目录复制到另一个目录 - Shell script copy file from one dir to another linux或Windows shell脚本上传文件并将其复制到另一台服务器 - linux or windows shell script to upload a file and copy it to another server 如何从文件列表中删除路径部分并将其复制到另一个文件中? - How to remove the path part from a list of files and copy it into another file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM