提取文件的列表,并创建包含该列表的新文件 [英] Extracting a list of files and creating a new file containing this list

查看:112
本文介绍了提取文件的列表,并创建包含该列表的新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是研究员,我在Unix中的技能命令是有限的。我目前正在处理中约含1000文件的文件夹,我要提取该文件夹的一些文件名,并创建另一个文件(配置文件)包含这些文件名。

I am a researcher and my skill in Unix commands is limited. I am currently dealing with a folder containing about 1000 files and I have to extract some filenames from this folder and create another file (configuration file) containing these filenames.

基本上,该文件夹有文件名的格式如下:

Basically, the folder has filenames in the following format :

1_Apple_A_someword.txt 
1_Apple_B_someword.txt 
2_Apple_A_someword.txt 
2_Apple_B_someword.txt 
3_Apple_A_someword.txt 
3_Apple_B_someword.txt

等等,直到

1000_Apple_A_someword.txt
1000_Apple_B_someword.txt

我只想把解压出来其中有Apple_A在其中的所有文件。此外,我想创建具有用于其每个的值是文件的名称,这些Apple_A文件标签(Unix的变量)另一个文件。此外,标签是文件名(一切,直到单词苹果),例如一部分,

I just want to extract out all files which have "Apple_A" in them. Also, I want to create another file which has 'labels' (Unix variables) for each of these "Apple_A" files whose values are the names of the files. Also, the 'labels' are part of the filenames (everything up until the word "Apple") For example,

1_Apple=1_Apple_A_someword.txt
2_Apple=2_Apple_A_someword.txt
3_Apple=3_Apple_A_someword.txt

等等......直到

and so on...till

1000_Apple=1000_Apple_A_someword.txt

你能告诉我一个单行的Unix命令做这个?也许用AWK和sed的

Could you tell me a one-line Unix command that does this ? Maybe using "awk" and "sed"

推荐答案

尝试

ls *Apple_A* | sed 's/\(\(.*Apple\).*\)$/\2=\1/'

这篇关于提取文件的列表,并创建包含该列表的新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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