Help with using sed, awk, nawk or tr

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.
djm
Participant
Posts: 68
Joined: Wed Mar 02, 2005 3:42 am
Location: N.Z.

Post by djm »

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
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

This is exactly why I hate sed, awk and Perl. It is almost unreadable. They are powerful but impossible to maintain. Assembler is great for the same reasons.
Mamu Kim
jzparad
Charter Member
Charter Member
Posts: 151
Joined: Thu Apr 01, 2004 9:37 pm

Post by jzparad »

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
djm
Participant
Posts: 68
Joined: Wed Mar 02, 2005 3:42 am
Location: N.Z.

Post by djm »

Thanks for checking it out Jim. I only get to feed my UNIX addiction Monday through Friday! :(

David
jzparad
Charter Member
Charter Member
Posts: 151
Joined: Thu Apr 01, 2004 9:37 pm

Post by jzparad »

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
Jim Paradies
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Jim,

that was an interesting link! I've become so used to using MKS toolkit that I never even looked at the market to see if there was any competition. If you or anyone else here has used both could you make a comparison?
jzparad
Charter Member
Charter Member
Posts: 151
Joined: Thu Apr 01, 2004 9:37 pm

Post by jzparad »

I've never used MKS - only cygwin. From the documentation of SFU, it seems to be designed more for enterprise integration whereas cygwin simply provides a unix shell along with all the familiar UNIX tools. I've only just started using SFU and, so far so good.
Jim Paradies
Post Reply