Board logo

标题: [文本处理] [已解决]批处理怎样把名字与手机号的位置统一? [打印本页]

作者: gcbgczhang    时间: 2019-7-5 11:07     标题: [已解决]批处理怎样把名字与手机号的位置统一?

本帖最后由 gcbgczhang 于 2021-7-31 14:20 编辑

拜见各位老师和前辈,我想要这样一个东西。
list.txt内容
王文龙        18219243233
苏洪秋        15330352670
张士祥        13695247007
石磊15015635907
田喜13484727896
赵亚明15019609194
哈春利13410982393
王翀        18320907528
13536622391        刘宁
13530693246        韩东
18125789469        陈彩凤
13530769943        常立春
...
要得到手机号后空一格跟上名字
18219243233 王文龙       
15330352670 苏洪秋       
13695247007 张士祥       
15015635907 石磊       
13484727896 田喜       
15019609194 赵亚明       
13410982393 哈春利       
18320907528 王翀       
13536622391        刘宁
13530693246        韩东
18125789469        陈彩凤
13530769943        常立春


不会弄啊,字符串截取吗,判断第一个字符是不是1,是的话截11位,然后载后面的,但是中间的空格长短不一,不知道先把中间的空格去掉再截取是不是可行
作者: zaqmlp    时间: 2019-7-5 12:12

  1. @echo off
  2. set info=互助互利,支付宝扫码头像,感谢赞助
  3. rem 有问题,可加QQ956535081及时沟通
  4. title %info%
  5. cd /d "%~dp0"
  6. set "input=list.txt"
  7. set "output=result.txt"
  8. powershell -NoProfile -ExecutionPolicy bypass ^
  9.     $text=[IO.File]::ReadAllLines('%input%',[Text.Encoding]::Default);^
  10.     $fs=New-Object System.IO.FileStream('%output%', [System.IO.FileMode]::Create);^
  11.     $sw=New-Object System.IO.StreamWriter($fs, [Text.Encoding]::Default);^
  12.     for($i=0;$i -lt $text.count;$i++){^
  13.         $m=[regex]::match($text[$i].trim(),'^^([^^\s\d]+)\s*?(\d+)');^
  14.         if($m.success){^
  15.             $sw.WriteLine($m.groups[2].value+\"`t\"+$m.groups[1].value);^
  16.         }else{^
  17.             $m=[regex]::match($text[$i].trim(),'^^(\d+)\s*?([^^\s\d]+)');^
  18.             if($m.success){$sw.WriteLine($m.groups[1].value+\"`t\"+$m.groups[2].value)};^
  19.         };^
  20.     };^
  21.     $sw.Close();$fs.Close();
  22. echo;%info%
  23. pause
复制代码

作者: Batcher    时间: 2019-7-5 12:53

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. (for /f "delims=" %%a in ('type "list.txt"') do (
  4.     set "str=%%a"
  5.     set "str=!str: =!"
  6.     set "str=!str: =!"
  7.     if "!str:~0,1!" equ "1" (
  8.         echo !str:~0,11! !str:~11!
  9.     ) else (
  10.         echo !str:~-11! !str:~0,-11!
  11.     )
  12. ))>"list_new.txt"
复制代码

作者: gcbgczhang    时间: 2019-7-5 18:42

回复 3# Batcher


    谢谢老师,用过了,得到了我想要的
作者: alexsq08a    时间: 2019-7-5 20:57

学习学习 学习学习




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2