gpt4 book ai didi

Linux 查找和替换(有条件)

转载 作者:太空宇宙 更新时间:2023-11-04 05:38:40 29 4
gpt4 key购买 nike

我有一个非常具体的要求,我发现很难做到,我需要查找并替换文件中的某些行,但问题是文本不同,唯一的好处是它们都有一个 .[扩展名]

例如:

30/07/2012  14:46            17,232 training program.DOCX.ddkhqvh
08/03/2011 20:57 31,664 nutritional program.XLS.ddkhqvh

需要:

F:/home/training program.DOCX.ddkhqvh
F:/home/nutritional program.XLS.ddkhqvh

我尝试使用 awk,但我很费劲。

最佳答案

这个怎么样:

$ awk '/^[0-9]+\/[0-9]+\/[0-9]+/ { sub(/^[^ ]+ +[^ ]+ +[^ ]+ +/,"F:/home/"); print; }' <file.txt
F:/home/ALLERGAN Recruitment tracking sheet Template.XLS.ddkhqvh
F:/home/Holding Letter 15May12.DOCX.ddkhqvh
F:/home/Amgen DBMS 2nd Mailing part 1 - Griifin Request Form.DOCX.ddkhqvh
F:/home/Amgen DBMS 2nd Mailing part 2 - Griifin Request Form.DOCX.ddkhqvh
F:/home/Database Letter, Reply Slip, 20070337, AMGXXXOST337,draft version 1, 19.03.12.DOC.ddkhqvh
F:/home/Previous DXA ladies 25.05.12.DOCX.ddkhqvh
F:/home/GP Letter, 20070337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/End of Study Thank You Letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/GP Letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/Interim Thank you letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/Welcome Letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/End of Study Thank You Letter,20070337, AMGXXXOST337, Version 1 Draft, 9th Feb 2012.DOC.ddkhqvh
F:/home/GP Letter,20070337, AMGXXXOST337, Version 1 Draft, 9th Feb 2012.DOC.ddkhqvh
F:/home/Interim Thank you letter,20070337, AMGXXXOST337, Version 1 Draft, 9th Feb 2012.DOC.ddkhqvh
F:/home/Welcome Letter, 20070337, AMGXXXOST337, Version 1 Draft, 9th Feb 2012.DOC.ddkhqvh
F:/home/End of Study Thank You Letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/example GPMS.DOC.ddkhqvh
F:/home/GP Letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/Interim Thank you letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/Welcome Letter, 20070337, AMGXXXOST337, Version 1, 16.02.12.DOC.ddkhqvh
F:/home/A5 EDUCATION LUNCH POSTERS - CAMPAIGN CODES.DOC.ddkhqvh
F:/home/Multiple choice Questionaire - Merseyside 26th Jan 2011.DOC.ddkhqvh
F:/home/Multiple choice Questionaire - Scotland 26th Jan 2011.DOC.ddkhqvh
F:/home/Multiple choice Questionaire - Wales 26th Jan 2011.DOC.ddkhqvh
F:/home/Multiple choice Questionaire Template 26th Jan 2011.DOC.ddkhqvh

这仅选取文件中具有初始日期的行,因此仅修改文件中列出的文件名。

关于Linux 查找和替换(有条件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27950668/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com