Page 1 of 1

Dataset pipes with sed edit

Posted: Wed Dec 21, 2011 5:54 am
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?

Re: Dataset pipes with sed edit

Posted: Wed Dec 21, 2011 8:38 am
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

Re: Dataset pipes with sed edit

Posted: Wed Dec 21, 2011 11:10 pm
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

Re: Dataset pipes with sed edit

Posted: Thu Dec 22, 2011 10:13 am
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.

Re: Dataset pipes with sed edit

Posted: Mon Feb 11, 2013 12:50 pm
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

Re: Dataset pipes with sed edit

Posted: Tue Feb 12, 2013 10:48 am
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?

Re: Dataset pipes with sed edit

Posted: Wed Feb 13, 2013 4:51 am
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

Re: Dataset pipes with sed edit

Posted: Wed Feb 13, 2013 9:28 am
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.

Re: Dataset pipes with sed edit

Posted: Wed Feb 13, 2013 11:19 am
by tsdjim
The file SYSPRI2 does have data, so why is it giving this error.

Re: Dataset pipes with sed edit

Posted: Wed Feb 13, 2013 12:17 pm
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.