LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   use sed to swap text in a string (not replace) (https://www.linuxquestions.org/questions/linux-newbie-8/use-sed-to-swap-text-in-a-string-not-replace-4175690660/)

Gebby_3 03-08-2021 09:00 AM

Quote:

Originally Posted by Gebby_3 (Post 6228422)
That syntax left the line unchanged.

This works but I am trying to simulate with sed (GNU sed version 3.02)
(Gawk GNU Awk 3.1.0)
gawk -F" - " "$0=$2FS$1" input file > output file

I am also trying to use SpellCheck but need to know how to implement this sed syntax and see the results.

SpellCheck

Load Random Example
#!/bin/bash
file1$ "left - right"
sed "s/\(.*\) - \(.2\)/\2 - \1/" file1$ > file2$
echo file2$

Syntax ok but how can I display the results here?
Please keep in mind I'm pretty green at RegEx
I am referencing all the suggested material given for help.

boughtonp 03-08-2021 09:10 AM

Quote:

Originally Posted by Gebby_3 (Post 6228422)
This works but I am trying to simulate with sed (GNU sed version 3.02)
(Gawk GNU Awk 3.1.0)

GNU Awk 3.1 is from 2002 and sed 3.0.2 was released in 1998!!

I refer again to my previous recommendation: ditch MKS Toolkit and just use MinGW (either via MSys2 or Git).

Then you will get current versions - and almost certainly the bug in Sed causing your problem will be solved.


Gebby_3 03-08-2021 10:08 AM

Latest Versions
 
Quote:

Originally Posted by boughtonp (Post 6228457)
GNU Awk 3.1 is from 2002 and sed 3.0.2 was released in 1998!!

I refer again to my previous recommendation: ditch MKS Toolkit and just use MinGW (either via MSys2 or Git).

Then you will get current versions - and almost certainly the bug in Sed causing your problem will be solved.


I will update my setup with GIT

Gebby_3 03-08-2021 11:24 AM

Quote:

Originally Posted by Gebby_3 (Post 6228490)
I will update my setup with GIT

Sorry. Older ver was my sed problem.
sed 4.0.7 worked fine.
My cygwin\bin ver won't work in my TCC shell but my UnixUtl\bin ver 4.0.7 works.

I know you mentioned that before.

I will see if GIT works in my TCC shell next.

--Thanks

boughtonp 03-08-2021 11:44 AM


 
Yep, I was fairly sure it would - I've used Sed enough on Windows and never had problems with the line ending problem, but it's not surprising that such an old version does.

Also, for clarity, what you're referring to as "GIT" is "Git for Windows", which is a bundle that includes multiple things: Git version control, GNU Bash shell, and mingw-w64 (which provides GNU coreutils and others) - referring to it as either "Git Bash" or "MinGW" should be less confusing.


Gebby_3 03-08-2021 06:18 PM

Quote:

Originally Posted by boughtonp (Post 6228541)
Yep, I was fairly sure it would - I've used Sed enough on Windows and never had problems with the line ending problem, but it's not surprising that such an old version does.

Also, for clarity, what you're referring to as "GIT" is "Git for Windows", which is a bundle that includes multiple things: Git version control, GNU Bash shell, and mingw-w64 (which provides GNU coreutils and others) - referring to it as either "Git Bash" or "MinGW" should be less confusing.


Yes, I got the Git for windows and extracted the portable version. Has all & more than I most likely will ever need.
This gets me over my major hurdles and ready for my next minor steps.
--Thanks to All that helped. So far the best help forum I've encountered and it's funny to see some of the same advisors on the other forums!
Glad we have people out there taking their time helping us green horns.
You haven't heard the last from me......


All times are GMT -5. The time now is 07:27 AM.