Board logo

标题: [文本处理] [已解决]批处理怎样将文本由一行换成多行? [打印本页]

作者: dxwyh1    时间: 2015-2-7 13:43     标题: [已解决]批处理怎样将文本由一行换成多行?

本帖最后由 dxwyh1 于 2015-2-7 16:00 编辑

有这么一行文本:"documentId":"150117025959-c1a2c9c6a4a094f182d0b03a535a9fb9","uploadTimestamp":"2015-01-17T02:59:59.000Z","created":"2015-01-17T02:59:59.000Z",
想从逗号处换成多行,形式如,

"documentId":"150117025959-c1a2c9c6a4a094f182d0b03a535a9fb9"
"uploadTimestamp":"2015-01-17T02:59:59.000Z"
"created":"2015-01-17T02:59:59.000Z"

向高手请教方法,谢谢!
作者: 愤怒的CMD    时间: 2015-2-7 14:09

echo "documentId":"150117025959-c1a2c9c6a4a094f182d0b03a535a9fb9","uploadTimestamp":"2015-01-17T02:59:59.000Z","created":"2015-01-17T02:59:59.000Z",|sed "s/,/\n/g"
作者: DAIC    时间: 2015-2-7 14:18

  1. @echo off
  2. (for /f "tokens=1-3 delims=," %%i in (1.txt) do (
  3.     echo,%%i
  4.     echo,%%j
  5.     echo,%%k
  6. ))>2.txt
复制代码

作者: DAIC    时间: 2015-2-7 14:19

  1. gawk "gsub(/,/,\"\n\")" 1.txt > 2.txt
复制代码

作者: dxwyh1    时间: 2015-2-7 15:50

DAIC 发表于 2015-2-7 14:19 gawk "gsub(/,/,\"\n\")" 1.txt > 2.txt


谢谢 DAIC 大侠!因为项目很多,采用了gawk这个“高大上”的方法。
同时感谢 愤怒的CMD 大侠的答疑。
作者: pcl_test    时间: 2015-2-7 15:54

回复 5# dxwyh1
如果问题解决,请在标题最前面标上[已解决]




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