Results 1 to 10 of 13
Hi All,
i wants to removing a space from my string by script.Like i have a=inder, if there is space like a= inder . before and after inder. Then i ...
- 01-08-2008 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 20
removing a space
Hi All,
i wants to removing a space from my string by script.Like i have a=inder, if there is space like a= inder . before and after inder. Then i wants to remove that space.Please tell me the script how to do this. Thanks ...
- 01-08-2008 #2
Could you give us a very short but complete example of a script in which you anticipate finding a string with such an unwanted space? This gives us a context in which to help you.
--
Bill
Old age and treachery will overcome youth and skill.
- 01-08-2008 #3Just Joined!
- Join Date
- Jan 2008
- Posts
- 20
Let i have a file aa.txt
$cat aa.txt
main= in (SPACE AT END AND START OF IN)
end= cc (SPACE AT END AND START OF CC)
How can i remove the space after = sign.
If you wants more specification, please let me know.
Thanks ...
- 01-08-2008 #4Linux Newbie
- Join Date
- Nov 2007
- Location
- Planet Earth
- Posts
- 152
Code:cat aa.txt | sed "s/= /=/g" > aa_replaced.txt
EOF
- 01-08-2008 #5For more information, follow this link for the Useless Use of Cat Award.Code:
cat aa.txt | sed "s/= /=/g" > aa_replaced.txt
Better:
You can eliminate multiple spaces thus:Code:sed "s/= /=/g" aa.txt > aa_replaced.txt
Code:sed "s/= */=/g" aa.txt > aa_replaced.txt
--
Bill
Old age and treachery will overcome youth and skill.
- 01-08-2008 #6Just Joined!
- Join Date
- Jan 2008
- Posts
- 20
Thanks
- 01-08-2008 #7Linux User
- Join Date
- Aug 2006
- Posts
- 458
using bash for not too large input file
Code:while read line do echo ${line/= /=} done < "file"
- 01-08-2008 #8Linux User
- Join Date
- Aug 2006
- Posts
- 458
for this case, i think it doesn't really matter, as performance wise, they are both quite the same. sed takes in standard input also.
Code:# wc -l file 15830725 file # time cat file | sed "s/= /=/g" > cattest real 0m47.755s user 0m46.723s sys 0m1.004s # time sed "s/= /=/g" file > sedtest real 0m48.812s user 0m46.343s sys 0m0.756s
- 01-08-2008 #9
Correct. It doesn't matter performancewise. But in general, the simpler the code, the better. The fewer pieces, the better. It makes code easier to maintain. It's this sort of practical esthetics that led Randal Schwartz to hand out awards for useless uses of cat. That's a bit of an ad hominem argument, sure, but he has a very good point, one with which I quite agree.
--
Bill
Old age and treachery will overcome youth and skill.
- 01-08-2008 #10Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote
