Board logo

标题: [文本处理] 批处理如何批量去除源代码的行号? [打印本页]

作者: netdzb    时间: 2020-11-10 12:57     标题: 批处理如何批量去除源代码的行号?

00060 void *xcalloc PARAMS ((size_t n, size_t s));
00061 void *xrealloc PARAMS ((void *p, size_t n));
00062 char *xstrdup PARAMS ((const char *str));
00063
00064 # define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
00065 # define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items)))
00066 # define XREALLOC(Ptr, Type, N_items) \
00067   ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items)))
00068
00069 /* Declare and alloc memory for VAR of type TYPE. */
00070 # define NEW(Type, Var)  Type *(Var) = XMALLOC (Type, 1)
00071
00072 /* Free VAR only if non NULL. */
00073 # define XFREE(Var)  \
00074    do {                 \
00075       if (Var)          \
00076         free (Var);     \
00077    } while (0)
00078
00079 /* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
00080 # define CCLONE(Src, Num) \
00081   (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num)))
00082
00083 /* Return a malloc'ed copy of SRC. */
00084 # define CLONE(Src) CCLONE (Src, 1)
00085
00086
00087 #endif /* !XALLOC_H_ */

求一个简单一点的命令,谢谢大家。
作者: smss    时间: 2020-11-10 14:44

  1. @Echo off&SetLocal EnableDelayedExpansion
  2. (for /f "delims=" %%i in (1.txt)do set x=%%i&set x=!x:~6!&Echo !x!)>2.TXT
  3. pause
复制代码

作者: qixiaobin0715    时间: 2020-11-10 14:52

参考http://bbs.bathome.net/thread-4580-1-1.html
  1. @echo off
  2. (for /f "delims=" %%a in (a.txt) do (
  3.     set "var=%%a"
  4.     setlocal enabledelayedexpansion
  5.     set var=!var:* =!
  6.     echo,!var!
  7.     endlocal
  8. ))>b.txt
  9. pause
复制代码

作者: qixiaobin0715    时间: 2020-11-10 15:54

本帖最后由 qixiaobin0715 于 2020-11-10 15:56 编辑

回复 1# netdzb
简单点
  1. @echo off
  2. (for /f "tokens=1,* delims= " %%a in (a.txt) do echo,%%b)>b.txt
  3. pause
复制代码

作者: Batcher    时间: 2020-11-10 23:05

回复 1# netdzb


推荐试试 sed.exe 命令行工具
http://bcn.bathome.net/s/tool/index.html?key=sed
  1. sed -r "s/^[0-9]+ {0,}//" 1.txt > 2.txt
复制代码

作者: netdzb    时间: 2020-11-11 12:37

回复 5# Batcher

+空格{0,} 表示什么意思?
作者: qixiaobin0715    时间: 2020-11-11 13:20

去掉行号数字紧邻的所有空格,若想只删除一个空格,可将空格保留,去掉{0,}即可。
作者: qixiaobin0715    时间: 2020-11-11 14:51

^[0-9]+.............行首一个或多个数字的集合
空格{0,}............. 0个或多个相连空格的集合
作者: netdzb    时间: 2020-11-11 20:53

回复 8# qixiaobin0715

谢谢你,我有点懂了。




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