如何以下列方式编辑文本文件? [英] How to edit a text file in the following way?

查看:118
本文介绍了如何以下列方式编辑文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个URL文本文件,例如archive.org/details/ightrailwaycon00parkgoog,但我需要将其中的任何一个更改为archive.org/download/lightrailwaycon00parkgoog/lightrailwaycon00parkgoog.pdf,

其中详细信息一词被下载替换,最后一个

斜杠后面的东西被/itself.pdf替换。我需要将其替换为文本文件的一般形式为archive.org/details/x.Please帮助我。



我尝试过: < br $> b $ b

记事本和一些文本编辑器,不像pad ++和EditPad.Pro

I got a text file of URLs like archive.org/details/ightrailwaycon00parkgoog ,but i need change any of them to a form like archive.org/download/lightrailwaycon00parkgoog/lightrailwaycon00parkgoog.pdf ,
in which the word "details" got replaced by "download",and the thing after the last
slash got replaced by "/itself.pdf".I need to do that to all the URLs in the text file with the general form of archive.org/details/x.Please help me with that.

What I have tried:

note pad and some text editors,like not pad++ and EditPad.Pro

推荐答案

使用Notepad ++,记录第一行上的宏然后将宏播放到文件的末尾。



或者,将文本文件加载到SQL Express或Access等数据库中,编写一些SQL来进行更改然后导出回文本文件。



也可以在Excel中执行类似的操作。



编辑 - 明确指示



1.将文件加载到记事本++

2.位置光标位于第1行的开头

3.单击菜单上的宏(或使用Alt-M)

4.单击开始录制

5.点击结束键(光标现在应该在第1行的末尾)

6.使用Ctrl + Shift + LeftArrow突出显示最后一个单词线路

7.按Ctrl + C复制该字

8.再次按结束键

9.键入 /

10.按Ctrl + V将单词粘贴到位

11.输入 .pdf

12.按下DownArrow键然后按Home键(光标现在位于第2行的开头)

13.单击宏,停止录制

13.根据需要多次单击播放(或Ctrl + Shift + P)或使用我在下面的评论中描述的播放到文件结尾选项

14 。完成后使用Ctrl + H获取Find&替换对话框

15.在查找内容框中键入 / details /

16.键入 / download / 在替换为框中

17.单击替换 A l

18保存文件



另外在Excel中

1.将文件粘贴到A栏中

2.在B列输入前几行的最后一位 - Excel会建议填充的其余部分显示为灰色(我不记得它的正确名称 - 类似Flash Fill)

3.点击灰色建议和Excel将为您填写整个B栏

4.在单元格C1类型 = A1& /& B1& .pdf

5.单击Cell C1并双击边框右下方的小实心方块,突出显示单元格

6. Excel将为您填写整个C栏

7.完成后使用Ctrl + H获取Find&替换对话框

8.在查找内容框中键入 / details /

9.键入 / download / 在替换为框中

10.单击替换 A l

11复制C列并使用您选择的编辑器将其粘贴回文件中
Use Notepad++, record a macro on the first line then play the macro to the end of the file.

Alternatively, load the text file into a database such as SQL Express or Access etc and write some SQL to make the changes then export back out to a text file.

Could do something similar in Excel too.

Edit - explicit instructions

1. Load the file into Notepad++
2. Position the cursor at the start of the 1st line
3. Click "Macro" on the menu (or use Alt-M)
4. Click "Start Recording"
5. Hit the End key (your cursor should now be at the end of line 1)
6. Use Ctrl+Shift+LeftArrow to highlight the last "word" of that line
7. Press Ctrl+C to copy that word
8. Press the End key again
9. Type /
10. Press Ctrl+V to paste the word into place
11. Type .pdf
12. Hit the DownArrow key then the Home key (cursor will now be at the start of line 2)
13. Click Macro, Stop Recording
13. Click Playback (or Ctrl+Shift+P) as many times as required or use the Play to end of file option that I described in my comments below
14. When complete use Ctrl+H to get the Find & Replace dialog
15. Type /details/ in the "Find What" box
16. Type /download/ in the "Replace with" box
17. Click Replace All
18. Save the file

Alternatively in Excel
1. Paste your file into column A
2. In Column B type the last bit for the first few rows - Excel will suggest the rest of the fill greyed out (I can't recall it's proper name - something like Flash Fill)
3. Click on the grey suggestions and Excel will fill in the whole of Column B for you
4. In cell C1 type =A1 & "/" & B1 & ".pdf"
5. Click in Cell C1 and double click the little solid square in the bottom right of the border highlighting the cell
6. Excel will fill in the whole of column C for you
7. When complete use Ctrl+H to get the Find & Replace dialog
8. Type /details/ in the "Find What" box
9. Type /download/ in the "Replace with" box
10. Click Replace All
11. Copy Column C and paste in back into your file using an editor of your choice


使用Notepad ++,您可以使用正则表达式进行搜索和替换。

请参阅< a href =http://docs.notepad-plus-plus.org/index.php/Regular_Expressions>如何在Notepad ++(教程)中使用正则表达式
With Notepad++ you can use regular expressions for search and replace.
See How to use regular expressions in Notepad++ (tutorial)


archive.org/details/ightrailwaycon00parkgoog
archive.org/download/lightrailwaycon00parkgoog/lightrailwaycon00parkgoog.pdf



确实用RegEx代替似乎是合适的。



只是一些有趣的链接来帮助构建和调试RegEx。

以下是RegEx文档的链接:

perlre - perldoc.perl.org [<小时ef =http://perldoc.perl.org/perlre.htmltarget =_ blanktitle =新窗口> ^ ]

以下是帮助工具的链接构建RegEx并调试它们:

.NET正则表达式测试程序 - 正则表达式风暴 [ ^ ]

Expresso正则表达式工具 [ ^ ]

RegExr:Learn,Build,&测试RegEx [ ^ ]

在线正则表达式测试器和调试器:PHP,PCRE,Python,Golang和JavaScript [ ^ ]

这个显示RegEx是一个很好的图表,它非常有助于理解RegEx的作用:

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]

这个网站也在一个漂亮的图表中显示正则表达式,但无法测试与RegEx匹配的内容:

Regexper [ ^ ]


Indeed a replace with RegEx seems appropriate.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx:
Regexper[^]


这篇关于如何以下列方式编辑文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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