首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用sed逆转word中的小写字符

如何使用sed逆转word中的小写字符
EN

Ask Ubuntu用户
提问于 2012-12-26 07:40:26
回答 2查看 576关注 0票数 1

使用sed反转行中的每个单词

代码语言:javascript
复制
   Description
   -----------

   The job to do is reversing every word of a line.

   that a word is a sequence of lowercase alphabets

   Raw Input
   ---------

   112358 is a fibonacci sequence...
   a test line
   124816 1392781
   final line...

   Desired Output
   --------------

   112358 si a iccanobif ecneuqes...
   a tset enil
   124816 1392781
   lanif enil...
EN

回答 2

Ask Ubuntu用户

回答已采纳

发布于 2012-12-26 10:29:38

这个sed脚本将完成以下工作:

代码语言:javascript
复制
#!/usr/bin/sed

# Put a \n in front of the line and goto begin.
s/^/\n/
bbegin

# Marker for the loop.
:begin

# If after \n is a lower case sequence, copy its last char before \n and loop.
s/\n\([a-z]*\)\([a-z]\)/\2\n\1/
tbegin

# If after \n is not a lower case sequence, copy it before \n and loop.
s/\n\([^a-z]*[^a-z]\)/\1\n/
tbegin

# Here, no more chars after \n, simply remove it before printing the new line.
s/\n//
票数 2
EN

Ask Ubuntu用户

发布于 2012-12-26 07:55:48

来自这里的教程是非常好的。样本:echo "nixcraft" | rev.对于SED部分,这里是这个链接

票数 0
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/232846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档