I have a list of words in a string:
str="SaaaaE SeeeeE SbbbbE SffffE SccccE"
I want to reverse it in order to get
"SccccE SffffE SbbbbE SeeeeE SaaaaE"
How I can do that with ash
?
I have a list of words in a string:
str="SaaaaE SeeeeE SbbbbE SffffE SccccE"
I want to reverse it in order to get
"SccccE SffffE SbbbbE SeeeeE SaaaaE"
How I can do that with ash
?
Yes, you can try these commands,
For string,
For the variable,
You could use awk:
Loop backwards through the fields, printing each one.
OFS
is the Output Field Separator (a space by default) andORS
is the Output Record Separator (a newline).I'm assuming that you don't want the order of the letters in each word to be reversed.
OUTPUT
**** Program to Reverse a String ***
Enter Here : I love My India
You have entered : I love My India
Reverse of String : India My love I
Here is an
awk
usingdo
while
(not much used here at Stackoverflow)No extra variable needed
i
if you need pure shell, no external tools, consider this:
Otherwise
tac
can help you straight away:or
Another pure bash solution: