0

hi,a question .. why does my script work as sh script.sh and not as ./script.sh ??

also,i was trying to write a script that would filter out a pattern in a .txt file and display the count of the same. Say my pattern is king, and there are 4 "king"s in the txt file .. also there are two "taking"s .. shouldnt the count be 6? m getting 4.
command -- grep -i "king" | wc -l

looking for healthy replies ..

~cheers

4
Contributors
4
Replies
22
Views
4 Years
Discussion Span
Last Post by chriswelborn
0

Add #!/bin/sh to the top of the script and make sure it's executable. If you are not sure about the path of sh then run which sh.

shouldnt the count be 6?

yes, it works fine for me. Maybe there are special characters?

0

hi,

why does my script work as sh script.sh and not as ./script.sh ?

has your script been made executable ?

my pattern is king, and there are 4 "king"s in the txt file .. also there are two "taking"s .. shouldnt the count be 6? m getting 4

please show input file. there are probably two or more on one or more lines.

Show your whole script too.

0

hi fellas .. yeah sh thingy works !!

inp file ..
""
king king
king
king
taking
taking
""

script :

while read line
do
grep -wi "king" | wc -l
done<abc.txt

0

grep -i "king" abc.txt | wc -l returns 5 (lines) -w returns 6 (words)

Edited by chriswelborn: added words

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.