Help with using sed, awk, nawk or tr
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Erk, I didn't mean to start a flame war! Hopefully the explanation of the script will help anyone new to the stream editor (sed) to understand how it's controlled.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Hence why, on reflection, I had offered the more robust alternative, (sed 's/^\[[0-9]\{1,\},[0-9]\{1,\}\]//g' 's/\(|\)\[[0-9]\{1,\},[0-9]\{1,\}\]/\1/g'), which deals with the coordinates at the start of the line explicitly and replaced "zero or more" instances of | with exactly one instance. (And yup the "\(\) & \1" portion is no longer necessary but I left it in so less of the suggestion had to be altered). I don't have a UNIX session to try it at the moment but if someone else has and cares to post whether it correctly renders the data example provided by Jim, I'd appreciate it.
(Far from a flame war Ray - I welcome constructive alternatives/improvements to postings).
David
(Far from a flame war Ray - I welcome constructive alternatives/improvements to postings).
David
Much better David!
Code: Select all
$ echo "[1,0]3009|[1,1]502" | sed -e 's/^\[[0-9]\{1,\},[0-9]\{1,\}\]//g' -e 's/\(|\)\[[0-9]\{1,\},[0-9]\{1,\}\]/\1/g'
3009|502
$ echo "[1,0]3009|[1,1][1,2]" | sed -e 's/^\[[0-9]\{1,\},[0-9]\{1,\}\]//g' -e 's/\(|\)\[[0-9]\{1,\},[0-9]\{1,\}\]/\1/g'
3009|[1,2]
Jim Paradies
Have a look at SFU from microsoft. It gives you a good UNIX shell for Windows and its free.
http://www.microsoft.com/windowsservers ... fault.mspx
http://www.microsoft.com/windowsservers ... fault.mspx
Jim Paradies