我的資料集示例“帶有 spaces.csv 的檔案名稱”(帶有匿名資料)檔案有多行。作為匯出的一部分,檔案的長度每天都在變化。
Patient Full Name Order Date Of Service Order Accession Number Day of Patient Birth Date Procedure Description Facility Name
AAAAA, Ms Joan 10/11/2022 xx.1111111 1 November 2000 Ultrasound Obstetric 22 Weeks Facility 1
BBBBB, Mr John 10/11/2022 xx.2222222 2 July 2000 Ultrasound Left Calf Facility 2
CCCCC, Mrs Anne 10/11/2022 xx.3333333 3 July 2000 X-ray Chest Facility 3
DDDDD, Master Jack 10/11/2022 xx.4444444 4 July 2000 Ultrasound Left Ankle Facility 4
....
試圖創建一個 BATCH 腳本來
- 閱讀每一行“帶空格的檔案名稱.csv”
- 洗掉在“titles.txt”(位于同一目錄)中找到的所有匹配行的字串
- 洗掉每行找到的第一個 TAB (\t),以及同一行之后的所有內容。
- 將結果復制到 Windows 剪貼板
例子:
AAAAA, Ms Joan 10/11/2022 xx.1111111 1 November 2000 Ultrasound Obstetric 22 Weeks Facility 1
BBBBB, Mr John 10/11/2022 xx.2222222 2 July 2000 Ultrasound Left Calf Facility 2
至
AAAAA, Joan
BBBBB, John
注意:標題后面始終跟有一個空格,因此如果在查找/洗掉中考慮了空格,則不會有從名稱中洗掉 Dr 或 Mr 等的風險。以下“titles.txt”的內容:
Mrs
Mr
Miss
Ms
Dr
Prof
A/Prof
在網上查看了其他腳本,但沒有一個與我正在做的完全匹配。對于我目前所處的位置來說也有點先進,但是無論如何都出現了對此的需求。
uj5u.com熱心網友回復:
@ECHO OFF
SETLOCAL
rem The following settings for the directories and filename are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
SET "filename1=%sourcedir%\q74397743.txt"
SET "filename2=%sourcedir%\q74397743_2.txt"
SET "destdir=u:\your results"
SET "outfile=
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/537185.html
標籤:批处理文件文本操作
上一篇:CMD前導零問題
