找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19815|回复: 4

[文本处理] 删除重复行的linux代码如何改成bat?

[复制链接]
发表于 2023-9-6 15:02:25 | 显示全部楼层 |阅读模式
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' 这条命令如何改成bat,我对linux不熟悉,谢谢!
发表于 2023-9-6 16:21:57 | 显示全部楼层
回复 1# 5872169


建议说清楚你想用这个代码实现什么功能?把测试文本一起发出来。
如果需要上传文件,可以用阿里云盘或百度网盘。

如果需要上传截图,可以找个图床,例如:
http://bbs.bathome.net/thread-60985-1-1.html
发表于 2023-9-6 22:49:09 | 显示全部楼层
意思是用bat实现那条sed命令的功能么?
是的话建议你下载一个windows下能用的sed
发表于 2023-9-7 09:52:00 | 显示全部楼层
复杂啊,真不如下个busybox-w32可以执行sed就好
  1. https://frippery.org/busybox/
复制代码
发表于 2023-9-7 16:03:11 | 显示全部楼层
回复 3# Five66


这个命令的作用是删除重复行,出自于大名鼎鼎的sed1line
http://www.pement.org/sed/sed1line.txt

中文版的解释
http://bbs.chinaunix.net/thread-306867-3-1.html#pid2031834

英文版的解释
https://catonmat.net/sed-one-liners-explained-part-three

使用[[:print:]]取代[ -~]可以解决某些环境下未能删除重复行的问题
https://stackoverflow.com/questions/5930246/what-does-this-sed-expression-from-todo-sh-do
Linux:
  1. sed -n 'G; s/\n/&&/; /^\([[:print:]]*\n\).*\n\1/d; s/\n//; h; P' 1.txt
复制代码
Windows:
  1. sed -n "G; s/\n/&&/; /^\([[:print:]]*\n\).*\n\1/d; s/\n//; h; P" 1.txt
复制代码
首先搞清楚几个基本命令的作用:
G Append hold space to pattern space.
d Delete pattern space. Start next cycle.
h Copy pattern space to hold space.
P Print up to the first embedded newline of the current pattern space.

然后使用 sedsed 执行一下观察详细过程:


批处理BAT脚本如何删除文本文件中重复的行
http://bbs.bathome.net/thread-5219-1-1.html
http://bbs.bathome.net/thread-5509-1-1.html
http://bbs.bathome.net/thread-4690-1-1.html
http://bbs.bathome.net/thread-5326-1-1.html
http://bbs.bathome.net/thread-4896-1-1.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-18 13:19 , Processed in 0.018447 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表