Can any1 suggest me, how to implement the "wc" word counting utility through bash shell script, i.e how to design a script working similar to "wc" command ??? Need it desperately, with all relevant options like -l, -c, -w ...

#!/bin/bash
wc $*

No seriously, why do you need this? This sounds suspiciously like a homework assignment.

this is not satisfactory !!! I wanted "wc" implementation without using "wc" .... Probably awk will do it..... Please suggest me other ways Its urgent !!!

And, obviously, you did not bother to read the rest of the post. The given answer was obviously a joke. I then went on to ask you why you need it. In a work situation I can't see this requirement coming up, so I have to assume it is for a homework assignment. If that is the case then I will continue with the tone of your last post and say piss-off. If there is a valid reason, then I will give you some real help, although it will not be a finished script in any way shape or form. So, as I asked in my first post, why do you need this?

Just so you know, I don't answer PM's. To give you a hint a while -- read loop and a sed command or two will allow you to completely emulate the wc command in a script without getting into any fancy convoluted constructs at all. It won't be all that effecient, but it won't be bad. Make an attempt using this info, post the code you tried, and I may help you further.

Another option: grep.

You have to show effort before we do your homework for you.

There is also a sed one hunk of code that does it as well.

You can also use a while ... do .. done loop.

Since the homework deadline has gone by and somebody may search.

One simple way with sed

# using sed for  wc -l 
sed -n  '$='  filename
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.