[英]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.