как поменять строчные буквы в слове, используя только sed

Поменять местами каждое слово строки с помощью sed

   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...
.
1
задан 26 December 2012 в 11:40

2 ответа

Этот скрипт Sed сделает работу:

#!/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//
0
ответ дан 26 December 2012 в 11:40

Учебное пособие из здесь очень хорошо. Образец: echo "nixcraft" | rev. И для части SED, вот из этой ссылки .

enter image description here

0
ответ дан 26 December 2012 в 11:40

Другие вопросы по тегам:

Похожие вопросы: