Dataset pipes with sed edit

Discussion of the Co:Z Toolkit Dataset Pipes utilities
Post Reply
tsdjim
Posts: 64
Joined: Fri May 07, 2010 2:21 am

Dataset pipes with sed edit

Post by tsdjim »

I am trying to pipe a dataset to sed with the following syntax but the output file is empty. Is this the right syntax to pipe into sed?

fromdsn -b DD:INPUT \
sed 's/fromstring/tostring/g' \
todsn -b DD:OUTPUT

If I need to have multiple sed statements how can I do that?
coz
Posts: 391
Joined: Fri Jul 30, 2004 5:29 pm

Re: Dataset pipes with sed edit

Post by coz »

You're pretty close - you just need to stand your pipes up a little straighter :)

Try this instead:

Code: Select all

fromdsn -b DD:INPUT |
sed 's/fromstring/tostring/g' |
todsn -b DD:OUTPUT
tsdjim
Posts: 64
Joined: Fri May 07, 2010 2:21 am

Re: Dataset pipes with sed edit

Post by tsdjim »

Can't get any straighter than that, but it still does not work. The edited data is not written to the output, just the original data.

sed needs to be told to send the edited data to the output file with > , something like in the the following statements, but it does not work, maybe the syntax again?.
And how can I have multiple sed commands.

fromdsn -b DD:INPUT |
sed 's/fromstring/tostring/g' > |
todsn -b DD:OUTPUT
coz
Posts: 391
Joined: Fri Jul 30, 2004 5:29 pm

Re: Dataset pipes with sed edit

Post by coz »

sed writes to stdout, which feeds the write end of the pipe in my example. You don't need any redirection.

I can't see what your DDs refer to, but you may not want to be using the -b switch. This tells fromdsn and todsn to process the data without any line separators, which may not be what you want. If you really intend to use -b, check to make sure that your DCBs are compatible.

Check out the -e and -f options for sed to issue multiple commands, or as an alternative look into using awk.
tsdjim
Posts: 64
Joined: Fri May 07, 2010 2:21 am

Re: Dataset pipes with sed edit

Post by tsdjim »

I have a z/os dataset SEDEDIT with multiple sed statements such as "sed -e -i .....| sed -e -i | sed -e -i" and a linux file tobedited.txt. I need to edit the tbeedited.file using the SEDEDIT and send the output to a dataset. I tried many syntax variations but I keep getting a message similar to /bin/bash DD:SEDFILE not found. What is the correct syntax?

tobeedited.file | //DD:SEDFILE todsn -b //DD:EDITED
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Re: Dataset pipes with sed edit

Post by dovetail »

So, if I understand, what you want is a command like this:

Code: Select all

cat tobeedited.file | 
  sed -e -i .....| sed -e -i | sed -e -i |
  todsn -b //DD:EDITED
(where the middle line comes from the DD:SEDFILE)

One way would be to use DD concatenation (if SEDFILE ended in a | )
//STDIN DD *
cat tobeeditted.file |
// DD DDNAME=SEDFILE
// DD *
todsn -b //DD:EDITED
//
Another way would be to use bash process substitution combined with "source" -
//STDIN DD*
cat tobeedited.file |
source <(fromdsn DD:SEDFILE) |
todsn -b //DD EDITED
//
BTW - Are you sure that you want "-b" on the todsn command?
tsdjim
Posts: 64
Joined: Fri May 07, 2010 2:21 am

Re: Dataset pipes with sed edit

Post by tsdjim »

I get the following error with this command:

cat SYSPRI2 | source <(fromdsn //DD:SEDFILE) | todsn -b //DD:OUT

todsn-client(11533)?E?: todsn(DD:OUT): error: no input data available, rc=103,
todsn-client(11533)?E?: server exit_code=103
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Re: Dataset pipes with sed edit

Post by dovetail »

that means that todsn didn't find any input data on stdin. The -z switch will eliminate this warning, but that probably isn't what you want.
tsdjim
Posts: 64
Joined: Fri May 07, 2010 2:21 am

Re: Dataset pipes with sed edit

Post by tsdjim »

The file SYSPRI2 does have data, so why is it giving this error.
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Re: Dataset pipes with sed edit

Post by dovetail »

apparently there isn't any output from the last pipeline.

Try taking off the "| todsn ..." and let the output go to stdout.
Maybe try putting the sed commands in the script directly first and debugging them there.
Post Reply