|
Home > Archive > Unix Shell > June 2005 > KSH: Problem with grep command used in counting the number of lines
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
KSH: Problem with grep command used in counting the number of lines
|
|
| manjunath.mallesh@gmail.com 2005-06-23, 7:51 am |
| Hi,
I have a problem in counting the number of lines on KSH.
Following the code i want to execute.
#!/bin/ksh
LF='
'
myStr="abc${LF}def${LF}"
myCnt=$(printf "%s\n" "${myStr}" | grep -v "^$" | wc -l | tr -d ' ')
myCnt1=$(printf "%s\n" "${myStr}" | grep -v "^[ ]*$" | wc -l | tr -d '
')
echo "count1 is $myCnt"
echo "count2 is $myCnt1"
The count value in myCnt and myCnt is different on some KSH versions.
On executing the above lines of code, output is
count1 is 0
count2 is 2
This happens specifically on KSH "version sh (AT&T Labs Research)
1993-12-28 m+"
Can anyone throw light on this.
Thanks in advance
Thanks & Regards
Manjunath
| |
| manjunath.mallesh@gmail.com 2005-06-23, 8:48 pm |
| Hi Bruce,
thanks for your reply.
the issue specifically occurs on KSH version "sh (AT&T Labs Research)
1993-12-28 m+" and not even on KSH version "sh (AT&T Labs Research)
1993-12-28 p" and other KSH versions like pdksh-5.2.14-22 and other
BASH versions.
Please let me know the reason.
| |
| manjunath.mallesh@gmail.com 2005-06-24, 2:48 am |
| Hi Bruce,
Thanks for the reply, the issue only seems to be with the $(.....), the
back ticks `...` work fine in this case.
Thanks a lot for the timely response.
Thanks & Regards
Manjunath
|
|
|
|
|