阅读文件列表复制删除的文件回 [英] Read list of files and copy deleted files back
问题描述
我做了一个善变的合并而注销的时候我需要在新的分支,所以我产生被删除的文件的列表,我现在试图建立一个shell脚本复制删除的文件回来,但到目前为止的一些文件是不working.The脚本的问题是
猫deltedfiles | xargs的-I {}的bash -c'切-d-f1{}| grep的-fqR和放大器;&安培;回波{}'
有人可以告诉我,我该如何纠正呢?
我刚刚得到削减一个错误,指出该文件不存在,整个行,我明白要被切断是把它当作一个文件。
编辑:
我创建的文件列表,并将其保存到使用汞状态的文本文件名为deletdfiles。
在剧本我会在与cp命令结束,这只是更换回声测试,如果我能得到ATLEAST它呼应。
该deltedfiles看起来喜欢这个
猫deltedfiles
我做了一个善变的合并而注销的时候我需要在新的分支,所以我产生被删除的文件的列表,我现在试图建立一个shell脚本来删除的文件复制回来,但到目前为止,它不是几个文件working.The脚本的问题是猫deltedfiles | xargs的-I {}的bash -c'切-d-f1{}| grep的-fqR和放大器;&安培;回波{}'
有人可以告诉我,我该如何纠正呢?
我刚刚得到削减一个错误,指出该文件不存在,整个行,我明白要被切断是把它当作一个文件。
编辑:
我创建的文件列表,并将其保存到使用汞状态的文本文件名为deletdfiles。
在剧本我会在与cp命令结束,这只是更换回声测试,如果我能得到ATLEAST它呼应。
该deltedfiles看起来喜欢这个
猫deltedfiles
- [R蟒蛇/ cmsintegration /事件/迁移/ 0002_improved_navigation.py
- [R蟒蛇/ cmsintegration /事件/迁移/ 0003_sitemap_fields.py
- [R蟒蛇/ cmsintegration /事件/迁移/ 0004_cache_differentiation.py
- [R蟒蛇/ cmsintegration /事件/迁移/ 0005_cms_displayables_seo.py
- [R蟒蛇/ cmsintegration /事件/迁移/ 0006_nav_has_changed.py
- [R蟒蛇/ cmsintegration /事件/迁移/ 0007_compute_nav_order.py
- [R蟒蛇/ cmsintegration /事件/迁移/ 0008_adding_mob_reg_link.py
运行上面的命令后,这是输出
切,R蟒蛇/ cmsintegration /事件/迁移/ 0002_improved_navigation.py:没有这样的文件或目录
切,R蟒蛇/ cmsintegration /事件/迁移/ 0003_sitemap_fields.py:没有这样的文件或目录
切,R蟒蛇/ cmsintegration /事件/迁移/ 0004_cache_differentiation.py:没有这样的文件或目录
切,R蟒蛇/ cmsintegration /事件/迁移/ 0005_cms_displayables_seo.py:没有这样的文件或目录
切,R蟒蛇/ cmsintegration /事件/迁移/ 0006_nav_has_changed.py:没有这样的文件或目录
切,R蟒蛇/ cmsintegration /事件/迁移/ 0007_compute_nav_order.py:没有这样的文件或目录
切,R蟒蛇/ cmsintegration /事件/迁移/ 0008_adding_mob_reg_link.py:没有这样的文件或目录
如果我理解正确的问题,这样的事情可以工作:
$同时读取-r _文件;不要回声$文件otherdir / $文件;完成< deltedfiles
蟒蛇/ cmsintegration /事件/迁移/ 0002_improved_navigation.py newfolder /蟒蛇/ cmsintegration /事件/迁移/ 0002_improved_navigation.py
蟒蛇/ cmsintegration /事件/迁移/ 0003_sitemap_fields.py newfolder /蟒蛇/ cmsintegration /事件/迁移/ 0003_sitemap_fields.py
蟒蛇/ cmsintegration /事件/迁移/ 0004_cache_differentiation.py newfolder /蟒蛇/ cmsintegration /事件/迁移/ 0004_cache_differentiation.py
蟒蛇/ cmsintegration /事件/迁移/ 0005_cms_displayables_seo.py newfolder /蟒蛇/ cmsintegration /事件/迁移/ 0005_cms_displayables_seo.py
蟒蛇/ cmsintegration /事件/迁移/ 0006_nav_has_changed.py newfolder /蟒蛇/ cmsintegration /事件/迁移/ 0006_nav_has_changed.py
蟒蛇/ cmsintegration /事件/迁移/ 0007_compute_nav_order.py newfolder /蟒蛇/ cmsintegration /事件/迁移/ 0007_compute_nav_order.py
蟒蛇/ cmsintegration /事件/迁移/ 0008_adding_mob_reg_link.py newfolder /蟒蛇/ cmsintegration /事件/迁移/ 0008_adding_mob_reg_link.py
替换回声
与 CP
,如果它产生正确的输出。
如果您只想复制都以单词开始的行中的文件研究
你
能做到这一点是这样的:
同时读取-r字母的文件_;做[[$信=R]]&放大器;&安培;回声$文件otherdir / $文件;完成< deltedfiles
另外,在一个更易读的格式:
同时读取-r字母的文件_
做
[[$信=R]]&放大器;&安培;回声$文件otherdir / $文件
完成< deltedfiles
I did a mercurial merge which deleted a few files which i need in the new branch so i generated a list of the deleted files and am now trying to build a shell script to copy the deleted files back but so far it is not working.The script is question is
cat deltedfiles | xargs -I {} bash -c 'cut -d" " -f1 "{}"|grep -Fq "R" && echo {}'
Can somebody tell me how do i correct this? I just get an error from cut saying that the file does not exist and the whole line which i understand to be is cut is treating it as a file.
EDIT: I created the list of files and saved it to a text file named deletdfiles using hg status. In the script i'll replace echo at the end with cp command this was just to test if i can atleast get it to echo.
The deltedfiles looks likes this
cat deltedfiles
I did a mercurial merge which deleted a few files which i need in the new branch so i generated a list of the deleted files and am now trying to build a shell script to copy the deleted files back but so far it is not working.The script is question is
cat deltedfiles | xargs -I {} bash -c 'cut -d" " -f1 "{}"|grep -Fq "R" && echo {}'
Can somebody tell me how do i correct this? I just get an error from cut saying that the file does not exist and the whole line which i understand to be is cut is treating it as a file.
EDIT: I created the list of files and saved it to a text file named deletdfiles using hg status. In the script i'll replace echo at the end with cp command this was just to test if i can atleast get it to echo.
The deltedfiles looks likes this
cat deltedfiles
R python/cmsintegration/events/migrations/0002_improved_navigation.py
R python/cmsintegration/events/migrations/0003_sitemap_fields.py
R python/cmsintegration/events/migrations/0004_cache_differentiation.py
R python/cmsintegration/events/migrations/0005_cms_displayables_seo.py
R python/cmsintegration/events/migrations/0006_nav_has_changed.py
R python/cmsintegration/events/migrations/0007_compute_nav_order.py
R python/cmsintegration/events/migrations/0008_adding_mob_reg_link.py
After running the above command this is the output
cut: R python/cmsintegration/events/migrations/0002_improved_navigation.py: No such file or directory
cut: R python/cmsintegration/events/migrations/0003_sitemap_fields.py: No such file or directory
cut: R python/cmsintegration/events/migrations/0004_cache_differentiation.py: No such file or directory
cut: R python/cmsintegration/events/migrations/0005_cms_displayables_seo.py: No such file or directory
cut: R python/cmsintegration/events/migrations/0006_nav_has_changed.py: No such file or directory
cut: R python/cmsintegration/events/migrations/0007_compute_nav_order.py: No such file or directory
cut: R python/cmsintegration/events/migrations/0008_adding_mob_reg_link.py: No such file or directory
If I understand the problem correctly, something like this could work:
$ while read -r _ file; do echo "$file" "otherdir/$file"; done < deltedfiles
python/cmsintegration/events/migrations/0002_improved_navigation.py newfolder/python/cmsintegration/events/migrations/0002_improved_navigation.py
python/cmsintegration/events/migrations/0003_sitemap_fields.py newfolder/python/cmsintegration/events/migrations/0003_sitemap_fields.py
python/cmsintegration/events/migrations/0004_cache_differentiation.py newfolder/python/cmsintegration/events/migrations/0004_cache_differentiation.py
python/cmsintegration/events/migrations/0005_cms_displayables_seo.py newfolder/python/cmsintegration/events/migrations/0005_cms_displayables_seo.py
python/cmsintegration/events/migrations/0006_nav_has_changed.py newfolder/python/cmsintegration/events/migrations/0006_nav_has_changed.py
python/cmsintegration/events/migrations/0007_compute_nav_order.py newfolder/python/cmsintegration/events/migrations/0007_compute_nav_order.py
python/cmsintegration/events/migrations/0008_adding_mob_reg_link.py newfolder/python/cmsintegration/events/migrations/0008_adding_mob_reg_link.py
Replace echo
with cp
if it produces the correct output.
If you only want to copy the files that are in a line that starts with the word R
you
can do it like this:
while read -r letter file _ ; do [[ $letter = "R" ]] && echo "$file" "otherdir/$file"; done < deltedfiles
Or in a more readable format:
while read -r letter file _
do
[[ $letter = "R" ]] && echo "$file" "otherdir/$file"
done < deltedfiles
这篇关于阅读文件列表复制删除的文件回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!