Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 755  / 1 Year ago, sat, january 14, 2023, 4:00:10

Reverse every word of a line using 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...

More From » bash

 Answers
0

This sed script will do the job:



#!/usr/bin/sed

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

# Marker for the loop.
:begin

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

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

# Here, no more chars after
, simply remove it before printing the new line.
s/
//

[#33512] Saturday, January 14, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
suspengn

Total Points: 477
Total Questions: 104
Total Answers: 100

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;