Hello,
In the page
http://docstore.mik.ua/orelly/unix/sedawk/ch02_05.htm
I followed the instructions to create a file called nameState and byState. The earlier sample commands with nameState work. I can also 'cat byState' and see the contents too. But when I run their sample command
|sed -f nameState list | byState
I get the error: byState: command not found
Even while typing the command itself, after the pipe, the byS does not auto complete giving a indication of a problem. What could this be? I can work with the file individually but after the pipe it does not show up. I can even do awk '{ print $0 }' byState and display the file contents.
|
2011/3/29 Rony gnulinuxist@gmail.com:
sed -f nameState list | byState
I get the error: byState: command not found
Do you have 'x' bit set on byState?
Do you have the directory containing byState in your PATH?
Binand
On Tue, Mar 29, 2011 at 08:58:43AM +0530, Rony wrote:
In the page
http://docstore.mik.ua/orelly/unix/sedawk/ch02_05.htm
I followed the instructions to create a file called nameState and byState. The earlier sample commands with nameState work. I can also 'cat byState' and see the contents too. But when I run their sample command
|sed -f nameState list | byState
I get the error: byState: command not found
Even while typing the command itself, after the pipe, the byS does not auto complete giving a indication of a problem. What could this be? I can work with the file individually but after the pipe it does not show up. I can even do awk '{ print $0 }' byState and display the file contents.
This is my byState:
#! /bin/sh awk -F, '{ print $4 ", " $0 }' $* | sort | awk -F, ' $1 == LastState { print "\t" $2 } $1 != LastState { LastState = $1; print $1 }'
And this works:
chmod +x ./byState sed -f nameState list | ./byState
HTH.
Kumar
On Tuesday 29 March 2011 10:42 AM, Kumar Appaiah wrote:
On Tue, Mar 29, 2011 at 08:58:43AM +0530, Rony wrote:
In the page
http://docstore.mik.ua/orelly/unix/sedawk/ch02_05.htm
I followed the instructions to create a file called nameState and byState. The earlier sample commands with nameState work. I can also 'cat byState' and see the contents too. But when I run their sample command
|sed -f nameState list | byState
I get the error: byState: command not found
Even while typing the command itself, after the pipe, the byS does not auto complete giving a indication of a problem. What could this be? I can work with the file individually but after the pipe it does not show up. I can even do awk '{ print $0 }' byState and display the file contents.
This is my byState:
#! /bin/sh awk -F, '{ print $4 ", " $0 }' $* | sort | awk -F, ' $1 == LastState { print "\t" $2 } $1 != LastState { LastState = $1; print $1 }'
And this works:
chmod +x ./byState
So I needed a ./byState along with the +x which I had done. I did that with the script from the site and at least it worked but gave a syntax error.
sed -f nameState list | ./byState
Thanks Kumar.
After I copied your script in byState it works. The difference was with some spaces. It looks like the site's scripts are not formatted and printed properly and they don't give any instructions on the extra steps. Becomes difficult for learners as more time is spent correcting their lapses.
On Tue, Mar 29, 2011 at 11:50:07PM +0530, Rony wrote:
Thanks Kumar.
After I copied your script in byState it works. The difference was with some spaces. It looks like the site's scripts are not formatted and printed properly and they don't give any instructions on the extra steps. Becomes difficult for learners as more time is spent correcting their lapses.
I must say that the formatting on the website is pretty bad. You might want to grab the files from here, though:
http://docstore.mik.ua/orelly/unix/sedawk/examples/index.htm
They look sane to me, but, again, some tweaking may be needed for your side.
All the best!
Kumar
P. S. sed and awk are life-changers, and the time you spend on mastering them is well worth the effort! :-)
On Wednesday 30 March 2011 02:02 AM, Kumar Appaiah wrote:
On Tue, Mar 29, 2011 at 11:50:07PM +0530, Rony wrote:
Thanks Kumar.
After I copied your script in byState it works. The difference was with some spaces. It looks like the site's scripts are not formatted and printed properly and they don't give any instructions on the extra steps. Becomes difficult for learners as more time is spent correcting their lapses.
I must say that the formatting on the website is pretty bad. You might want to grab the files from here, though:
http://docstore.mik.ua/orelly/unix/sedawk/examples/index.htm
They look sane to me, but, again, some tweaking may be needed for your side.
That link was very nice. They have given the scripts in the correct format. In the other pages they have made multiple lines into one long line and created confusion.
All the best!
Kumar
P. S. sed and awk are life-changers, and the time you spend on mastering them is well worth the effort! :-)
Thanks for the tips.
2011/3/29 Rony gnulinuxist@gmail.com:
After I copied your script in byState it works. The difference was with some spaces. It looks like the site's scripts are not formatted and printed properly and they don't give any instructions on the extra steps. Becomes difficult for learners as more time is spent correcting their lapses.
I think what changed was that you started doing ./byState. As I said before, you need to have "." in your path or should do ./program (having "." in your path brings in its own set of problems, so the latter is indeed preferred).
A point to note is that this book assumes a level of familiarity with Unix - how to invoke commands, how to set path etc. You can't blame the book for that.
Binand
On Wed, Mar 30, 2011 at 06:49:10AM +0530, Binand Sethumadhavan wrote:
A point to note is that this book assumes a level of familiarity with Unix - how to invoke commands, how to set path etc. You can't blame the book for that.
Frankly, I don't see why I wouldn't blame the book for this. In the least, they should mention somewhere that one should have some shell familiarity. The preface makes no such statements on the assumptions.
A mere two or three lines of chmod +x byState and adding a "./" would have been a much better option, given that these are uniform across all Unix-like operating systems.
Kumar
On Wednesday 30 March 2011 06:49 AM, Binand Sethumadhavan wrote:
A point to note is that this book assumes a level of familiarity with Unix - how to invoke commands, how to set path etc. You can't blame the book for that.
True, but the commands are in black and white using different fonts to denote the actual command. Anyway the index page link will help me verify things.