Using sed in bash to remove whitespace
Hi, I'm new to sed and need to be able to use it in a bash script to remove whitespace from some html code. I've got a variable called regionWholeLine in my script:
(because the forum automatically deletes them I have to represent whitepace with ....) .................................................<strong>Asia-Pacific</strong><br /> so I used the following code: regionWholeLine="`echo "$regionWholeLine" | sed -e :a -e 's/^[ .............. ]*<strong/<strong /'`" However, it doesn't seem to work and I've no idea why, because elsewhere in my script I use similar code to do exactly the same thing: titleWholeLine="`echo "$titleWholeLine" | sed -e :a -e 's/^[ ......... ]*<td class/<td class/'`" works on: .......................................................<td class="title"> Any ideas why I'm having problems? Thanks, ~James~ |
If you use code tags
[ c o d e ] ......... [ / c o d e ] (without the spaces ) the forum won't chop off leading blanks. Here is a start: Code:
tmp=`echo "$regionWholeLine" | sed 's/ / /g' | sed 's/^[ ]//' ` |
How about this:
test.txt Code:
Code:
# cat test.txt | sed 's/^[ ]*//' |
Ah! I figured it out! Thanks for your replies, it helped me understand a little better about how sed works (I could only find very complicated documentation). It was all because I was using a space, instead of a tab inbetween the [ ] :)
Cheers, ~James~ |
All times are GMT -5. The time now is 09:24 AM. |