简体   繁体   English

是否有 linux 命令循环遍历目录中的文件,然后将所有文件名和内容写入 csv 文件?

[英]Is there a linux command loop through files in a directory then write all files names and content into csv file?

I have a directory with 100 thousand files (each file has only one line), I need a fast way to go through all files to write one csv file that contains two columns: File Name, Content of the File.我有一个包含 10 万个文件的目录(每个文件只有一行),我需要一种快速浏览所有文件的方法来编写一个包含两列的 csv 文件:文件名、文件内容。

File_A: This is File one. File_A:这是文件一。

File_B: This is file two. File_B:这是文件二。

I need to get a csv file: File_A This is File one.我需要得到一个 csv 文件: File_A 这是文件一。 File_B This is file two. File_B 这是文件二。

Just do grep . * > ../output.csv只是做grep . * > ../output.csv grep . * > ../output.csv to create a file with a : separator. grep . * > ../output.csv创建一个带有:分隔符的文件。 If you want to use a different delimiter, pipe it to sed .如果要使用不同的分隔符,请将其通过管道传输到sed Some grep provide a --null option to use a zero byte as the delimiter.某些 grep 提供了一个--null选项来使用零字节作为分隔符。

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

相关问题 循环浏览目录中的所有文件? - Loop through all files in a directory? Linux命令为目录中的所有文件提供文件扩展名 - Linux command to give all files in a directory a file extension linux命令:显示所有文件的内容 - linux command: show content of all files 在Linux目录中创建新文件,其中包含该目录中文件的名称 - Create new file in Linux directory with names of files in that directory 我如何删除“ <MAXROWS/> 通过linux / unix命令从目录中所有30个文件中获取字符串? - How can i remove “<MAXROWS/>” string from all 30 files in my directory through linux / unix command? 从Linux中的两个文件内容重命名文件名 - Renaming file names from two files content in linux 将Linux命令递归应用于单一(.sh)类型目录中的所有文件 - Apply Linux command recursively to all files in directory of single (.sh) type Linux命令在目录中查找具有相同名称但扩展名不同的所有文件? - Linux command to find all the files with same name but different extension in a directory? 循环遍历多个文件夹以执行命令,然后写入另一个目录中的文件 - Loop through multiple folders to perform a command then write to file in another directory 使用*解析文件。 需要写文件名 - Using * to parse through files. Need to write file names
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM