|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
Originally posted by 无奈何 at 2006-11-7 11:09:
我也补个 sed 的,文件不要过于巨大。
sed -re :a -e "N;$!ba;s/(*)\n(.*)\n(.*)/\3\n\2\n\1/"
sed 下载:http://www.student.northpark.edu/pemente/s ...
斑竹的sed用法看不懂还,我复制回去查查资料先
Originally posted by 无奈何 at 2006-11-7 11:09:
I'll also add one for sed, but the file shouldn't be too huge.
sed -re :a -e "N;$!ba;s/(*)\n(.*)\n(.*)/\3\n\2\n\1/"
Sed download: http://www.student.northpark.edu/pemente/s ...
The moderator's sed usage is not understandable, I'll copy it back and check the information first
|
|
2006-11-9 02:11 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
 『第 17 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal ENABLEDELAYEDEXPANSION
set file=a.txt
for /f "delims=: tokens=1,*" %%i in ('findstr /n .* "%file%"') do set "%%i=%%j" & set num=%%i
set "str=!%~1!"
set "%~1=!%~2!"
set "%~2=%str%"
for /l %%i in (1,1,%num%) do if defined %%i (echo.!%%i!) else echo.
pause
利用上面的原理,实现3,-3并不难。
刚才写上面的东西的时候朋友喊我去帮忙做了系统的, 不知道有无bug,反正原理就那些了。
@echo off
setlocal ENABLEDELAYEDEXPANSION
set file=a.txt
for /f "delims=: tokens=1,*" %%i in ('findstr /n .* "%file%"') do set "%%i=%%j" & set num=%%i
set "str=!%~1!"
set "%~1=!%~2!"
set "%~2=%str%"
for /l %%i in (1,1,%num%) do if defined %%i (echo.!%%i!) else echo.
pause
Using the above principle, it's not difficult to implement 3, -3.
I was writing the above thing when a friend called me to help with the system. I don't know if there are bugs, but the principle is just those.
|
|
2006-11-9 10:50 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
版主让行号直接模拟数组变量的方法真巧妙~:)
能看到这么好玩的内容简直太过瘾了~:)
The method that the moderator let the line numbers directly simulate array variables is really clever~:)
It's so enjoyable to be able to see such interesting content~:)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2006-11-9 11:47 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
我在想 3742668 斑竹的代码在行中遇到 | 会不会执行~我试了好象不可以
I'm wondering if the code of moderator 3742668 will be executed when encountering | in the line. I tried and it seems not possible
|
|
2006-11-11 07:55 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
我在想 3742668 斑竹的代码在行中遇到 | 会不会执行~我试了好象不可以
有无加参数?
我这里测试正常。
I'm wondering if the code of moderator 3742668 will execute when encountering | in the line ~ I tried and it seems not possible
Any parameters added?
It tests normally here.
|
|
2006-11-13 06:40 |
|
|
amao
中级用户
  
积分 316
发帖 152
注册 2006-6-18
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
无奈何斑竹的代码在解决小文本时简洁利索;
vkill的代码在文本最后一行没有回车(换行)符时,会出错;
我也发一下我的代码吧,基于sed的
@echo off
sed -n "$!d;G;P" a.txt> temp.txt
sed "1d;$d" a.txt>> temp.txt
sed q a.txt>> temp.txt
type temp.txt
pause
它不管文本最后一行有无回车(换行)符都起作用
Last edited by amao on 2007-2-2 at 05:18 PM ]
There's no help for it that the code of the moderator is concise and neat when dealing with small texts;
The code of vkill will go wrong when there is no carriage return (newline) character in the last line of the text;
I'll also post my code, based on sed
@echo off
sed -n "$!d;G;P" a.txt> temp.txt
sed "1d;$d" a.txt>> temp.txt
sed q a.txt>> temp.txt
type temp.txt
pause
It works no matter whether there is a carriage return (newline) character in the last line of the text or not
Last edited by amao on 2007-2-2 at 05:18 PM ]
|
|
2007-2-2 16:33 |
|
|
anqing
高级用户
   
积分 859
发帖 413
注册 2006-8-14
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
p能写成这样的要求,真不容易
It's really not easy to be able to write the requirements like this
|
|
2007-2-3 00:02 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
Originally posted by amao at 2007-2-2 16:33:
无奈何斑竹的代码在解决小文本时简洁利索;
vkill的代码在文本最后一行没有回车(换行)符时,会出错;
我也发一下我的代码吧,基于sed的
@ech ...
兄也喜欢sed ?呵呵
Originally posted by amao at 2007-2-2 16:33:
There is no help for it, the moderator's code is concise and neat when solving small texts;
vkill's code will have an error when there is no carriage return (newline) character in the last line of the text;
I will also post my code, based on sed
@ech ...
Brother also likes sed? Hehe
|
|
2007-2-3 05:06 |
|
|
amao
中级用户
  
积分 316
发帖 152
注册 2006-6-18
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
Originally posted by vkill at 2007-2-3 05:06:
兄也喜欢sed ?呵呵
正在努力学习中
Originally posted by vkill at 2007-2-3 05:06:
You also like sed? Hehe
I'm studying it hard
|
|
2007-2-3 11:06 |
|
|
ArchieYao
新手上路

积分 4
发帖 2
注册 2007-11-29
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
顶上来问一下
如楼主给出的文本内容,如果我要互换含"张三" 和"小二"的行,怎么处理
想听听用sed的处理办法:)
Bump up to ask. If I want to swap the lines containing "Zhang San" and "Xiao Er" according to the text content given by the LZ, how to handle it? I want to hear the processing method with sed :)
|
|
2007-11-29 23:22 |
|