Batch file to add characters to beginning and end of each line in txt file

后端 未结 4 1360
小鲜肉
小鲜肉 2020-12-06 06:50

I have a text file, I was wondering anyone have a batch file to add \" to the beninning and \", at the end of each line in a text file?

For example I have



        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 07:37

    Off the top of my head, in Linux, you can...

    $ for each in `cat filename` ; do echo \"$each\", ; done >> newfilename
    
    "1",
    "2",
    "3",
    "4",
    "5",
    

    Edited - since it's for Windows, this did the trick for me:

    @echo off
    setLocal EnableDelayedExpansion
    
    for /f "tokens=* delims= " %%a in (filename.txt) do (
    echo "%%a", >>newfilename.txt
    )
    

提交回复
热议问题