1833758 Members
2564 Online
110063 Solutions
New Discussion

Re: Scripting:Pls help.

 
SOLVED
Go to solution
Dewa Negara_4
Regular Advisor

Scripting:Pls help.

Hi All,

Pls help. How can we exclude an empty space on a file, so the script won't read the empty space. Example, I have a file called file01 below :

one
two
#tree

four

five

If in the script I use this command #grep -v "#" file01|while read X, the empty space will be read by the script and give me the wrong result. How can we exclude the empty space on the command #grep -v "#" file01|while read X

Pls help.
Thanks in advance.

Best Regards,
Negara
Santos
8 REPLIES 8
Dave La Mar
Honored Contributor

Re: Scripting:Pls help.

Well, asumming the other entries contain no spaces:
grep -v " " or grep -v " "
etc.
Go for it. Best of luck.
There a multitude of ways to do this. I am just giving you a down and dirty quick fix.

Regards,
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Dave La Mar
Honored Contributor

Re: Scripting:Pls help.

Negara:
My second grep should have shown multiple spaces between the quotes. Don't know why it did not.
May be a forums issue for Dan.
dl
"I'm not dumb. I just have a command of thoroughly useless information."
Dewa Negara_4
Regular Advisor

Re: Scripting:Pls help.

Dave,

Thanks. It still not working properly.

Can you pls help to give me other methods?

Thanks.
Negara
Santos
curt larson_1
Honored Contributor

Re: Scripting:Pls help.

awk '/^[^#]/ {print;}' file01 |
while read X

this will strip out empty lines and lines begining with #
curt larson_1
Honored Contributor

Re: Scripting:Pls help.

sed -e '/^$/d' -e '/.*#.*/d' |
while read X
curt larson_1
Honored Contributor
Solution

Re: Scripting:Pls help.

grep -vE "^$|#" file01 |
while read X
isaac_loven
Frequent Advisor

Re: Scripting:Pls help.

You Must Get the book: "UNIX POWER TOOLS"
(also available second hand )
Also u can use the web. Check out:
http://www.uwsg.iu.edu/UAU/advcomm/SED.html

Please Assign points.
Isaac.
Dewa Negara_4
Regular Advisor

Re: Scripting:Pls help.

Thanks for your great help.

It looks fine for me now.

Thanks again.

Best Regards,
Negara
Santos