简体   繁体   English

如何将标题和预告片从文件移动到另一个文件?

[英]How to move Header and Trailer from files to another file?

I have around 100 text files with close to thousand records in a folder.我有大约 100 个文本文件,文件夹中有近千条记录。 I want to copy header and trailer of these files into a new file with the file name of respective file.我想将这些文件的头和尾复制到一个新文件中,文件名分别为相应文件的文件名。

So the output i want is as所以我想要的输出是

File_Name,Header,Trailer

is this possible using Unix or Python?这可以使用 Unix 或 Python 吗?

一种方法是使用包含文件的文件夹中的 bash shell:

for file in *; do echo "$file,$(head -1 $file),$(tail -1 $file)"; done

带有别名的 PowerShell 核心单行

 gci *.txt |%{"{0},{1},{2}" -f $_.FullName,(gc $_ -Head 1),(gc $_ -Tail 1)}|set-content .\newfile.txt

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

相关问题 删除 header 和预告片后如何将文件从一个位置复制到 S3 中的另一个位置 - How to copy a file from one location to another location in S3 after removing header and trailer 如何将文件从一个目录移动到另一个目录? - How to move files from a directory to another? Python3 连接多个文件并忽略头部和尾部记录 - Python3 Concatenate multiple files and ignore header & trailer records 过滤 Header 2 行和 1000 个大文件中的 Trailer 1 行 pyspark - Filter Header 2 rows and Trailer 1 row in 1000 of huge files pyspark 如何将文件从一个目录移动到另一个目录? - How to move a file from one directory to another? 如何在python中将文本文件中列出的文件从一个文件夹移动到另一个文件夹 - How to move files listed in a text file from one folder to another in python 您将如何按文件类型将文件从一个目的地移动到另一个目的地? - how would you move files from one destination to another sorted by file type? 如何将文件从一个文件夹从python移动到另一个文件夹 - How to move Files from one folder to another folder from python zlib解压和压缩时如何保留头部和尾部 - How to keep the header and trailer while zlib decompress and compress 如何将特定文件从一个文件夹移动到另一个文件夹? - how to move specific files from one folder to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM