Results 1 to 10 of 12
a small question - how can we remove spaces within a file without making use another file?...
- 07-16-2008 #1Just Joined!
- Join Date
- Jun 2006
- Posts
- 16
remove spaces
a small question - how can we remove spaces within a file without making use another file?
- 07-16-2008 #2
[dir@host] $ cat av
giga g hhh
hira moti giga gi gaa giga fi fa
[dir@host] $ sed "s/[ \t][ \t]*//g" av|tee av
gigaghhh
hiramotigigagigaagigafifa
[dir@host] $ cat av
gigaghhh
hiramotigigagigaagigafifa
[dir@host] $
- 07-16-2008 #3
To just remove multiple spaces...not single space... just replace/substitute [ \t][ \t] with a single space ..i.e.
sed "s/[ \t][ \t]*/ /g" av|tee av
a space added...^ (within / and /)
- 07-17-2008 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
If you really want to remove all space characters from a file in situ
will do it.Code:sed -i "s/ *//g" filename
- 07-17-2008 #5Just Joined!
- Join Date
- Jun 2006
- Posts
- 16
the tee is printing out the file at the output. Do I need to put >/dev/null or am i doing wrong
-i option is not available to mesed "s/[ \t][ \t]*//g" av|tee av
sed -i "s/ *//g" filename
- 07-18-2008 #6Linux User
- Join Date
- Aug 2006
- Posts
- 458
sometimes you just have to be practical.
what's wrong with that?Code:sed "s/[ \t][ \t]*//g" av > temp mv temp original_file_name
sed with the -i option will do the same thing at the background for you.
- 07-18-2008 #7Just Joined!
- Join Date
- Jun 2006
- Posts
- 16
Didnt wanted to use an additional filesometimes you just have to be practical.
Code:
sed "s/[ \t][ \t]*//g" av > temp
mv temp original_file_name
-i option for sed is not supported . May be old version and needs to be upgradedwhat's wrong with that?
sed with the -i option will do the same thing at the background for you
- 07-18-2008 #8Linux User
- Join Date
- Aug 2006
- Posts
- 458
if you do not have -i option, then no go for your version of sed. Even if you have the latest sed with -i option, it is also going to create an "invisible" temp file for you. so what's the big problem ? just use whatever you have to get the job done.
- 07-18-2008 #9
You could use tr:
Where temp is the name of the fileCode:echo $(cat temp | tr -d "\ ") > temp
Linux User #453176
- 07-18-2008 #10Linux User
- Join Date
- Aug 2006
- Posts
- 458


Reply With Quote
