Creating a Script

More
27 Mar 2013 07:00 #31951 by arvidb
Replied by arvidb on topic Creating a Script

*snip*
I guess a more clever approach would be to find the Z or z and read in up to the next letter or end of line then append the W part.


That's pretty much what the sed script does:

s|Z\([-.0-9]*\)|Z\1 W\1|g

s = use sed's replace function
| = separator
Z\([-.0-9]*\) = regular expression that matches 'Z' and then an arbitrary number of '-', '.' and/or digits, and stores the result between the quoted parentheses.
| = separator
Z\1 W\1 = replace it with 'Z' and the stored result, a space and a W and the stored result again.
| = separator
g = do it globally, not only one match per line.
The following user(s) said Thank You: Todd Zuercher

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 07:05 #31952 by arvidb
Replied by arvidb on topic Creating a Script

When I try to use it as a filter this happens.


Looks like you have a garbage character in the script? Try removing the end of the
#! /usr/bin/env python
line, and retype it. Make sure to delete just past the end, so that the next line pops up, and then add a fresh newline.

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 09:31 #31953 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script

The script with print "%s" % item should not be run from the command line.

I see you must have ran the other file a few times as I see the converted files.

Are you using a stock 10.04 LiveCD install? It seems to be choking on the location of python in the first line of the script.

John


Yes it is a stock live CD install.

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 09:40 #31954 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script

Maybe because I forgot to quote the file name parameter in the script. Is there by any chance a space in your network file path?


Its at work and I am at home now, but I am pretty sure there are spaces in the network path. I'll give these hints a try tomorrow.

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 18:16 #31960 by BigJohnT
Replied by BigJohnT on topic Creating a Script
Just to be sure here is a compressed version of the script.

John
Attachments:

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 19:54 #31962 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
Adding the quotes to the sed line fixed that for me, so that works now.

However I still can't get the python script to work :(

Would it be possible to use the sed line with some other stuff to add a pre and postamble as well.

We have several similar machines that run more or less the same code with the only real difference being variations in the pre and posts.
If I could have the machines filter and add their unique parts when opening files I would only have to maintain a single set of files instead of 7 different ones.

I thought that this might be easier to do with the python script, but if I can't even get one to run, then I'll have to look for other options.

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 20:14 #31963 by BigJohnT
Replied by BigJohnT on topic Creating a Script
You did get the script that creates a new file to run from the terminal right?

I wish I could duplicate your error but I can not... I've tried all kind of file names and it just works for me.

Are there any windoze computers involved with the file handling?

John

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 20:22 #31964 by BigJohnT
Replied by BigJohnT on topic Creating a Script
What does

which python

return in a terminal?

John

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 20:25 #31965 by BigJohnT
Replied by BigJohnT on topic Creating a Script
I can get a similar error by changing the first line of the script...

John

Please Log in or Create an account to join the conversation.

More
27 Mar 2013 20:26 #31966 by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
Yes I was able to get the script that runs from terminal to run fine. I think that maybe the problem I was haveing with line feeds was that the files I was trying to convert had Windows style line feeds.

Please Log in or Create an account to join the conversation.

Time to create page: 0.202 seconds
Powered by Kunena Forum