I have a variable that calls in a string from txt file. Problem is the string comes with an abundance of white spaces trailing it. Is there any easy way to trim the tailing white spaces off at the end? Thanks in advance.
#!/bin/ksh
a='foo '
echo "Before->[${a}]"
a="${a%% *}"
echo "After->[${a}]"
Thanks for quick response! When I do this I get a bad substitution error... do I need to put the % or the *? What is their function?
alternatively in Python
#!/usr/bin/python
for lines in open("txtfile.txt"):
lines = lines.strip()
print lines
make sure you're in 'ksh' - '#!/bin/ksh'
or:
#!/bin/sh
a='fooo '
echo "Before->[${a}]"
a=`echo "${a}" | sed 's/ *$//'`
echo "After->[${a}]"
Thanks! I understand now.. but i run into a problem, let's say my variable stores the following:
a='I like foo '
I would need something where the white space after foo disappears - is this doable?
Nevermind! It works! Thanks guys. You rock!
my file contain blank spaces between then
Example
sssss ssss
ssssa1 1212
asaasasa asasa
asasa dmddmfdmcc
cvcvcedfdefd
dfdfd
dfdfdfd
dfdfdfdefe
sed -e "/^$/d" -e "/^ *$/d" file
Quite simply
sed -e "/^ *$/d" file
or if space may be tabulation :
sed -e '/^[[:space:]]*$/d' file
Jean-Pierre.