Removing asterisks from a file
Karl Larsen
k5di at zianet.com
Thu Oct 16 11:44:00 UTC 2008
James Gray wrote:
>
> On 16/10/2008, at 4:13 PM, Ranmadhu Wijayatilaka wrote:
>
>> James Gray wrote:
>>> sed "s#*##g" file.txt > new_file.txt
>>>
>>> That will remove the asterisks from "file.txt" and dump the result
>>> into "new_file.txt"
>> Fantastic! Thank you. That does what I need. For my benefit, how does
>> that command work?
>
> The basic syntax for sed is:
>
> sed [expression] [file]
>
> So [expression] is applied against [file] and the result dumped to
> standard out. So by redirecting STDOUT using ">" it writes the result
> to the file "new_file.txt" instead of the screen.
>
> Now the real magic in [expression] that I used is in putting the whole
> thing in double quotes to avoid the shell (bash etc) trying to expand
> the "*" and also avoids the need to escape characters. However the
> "s" command I gave sed means substitute:
>
> s/substitution pattern/replacement/ (although I used "#" instead of
> "/"). So in this case sed will replace the FIRST instance
> "substitution pattern" with "replacement" on each line it occurs. If
> there is more than one occurrence on any line, you need to suffix the
> substitution command with "g" to make it globally replace ALL
> occurrences on each line.
>
> There are plenty of really good sed tutorials online just google "sed
> primer".
>
> Regards,
>
> James
And if you do not like all that //\./\ which is confusing in the
most basic case, from Applications bring up your file in gedit (Text
Editor). Observe all the * and in gedit and then click on Search and
then Replace or (Ctrl-H) then tell it to Replace with a space and click
on replace all. This is harder to type than it is to do :-)
Karl\/
--
Karl F. Larsen, AKA K5DI
Linux User
#450462 http://counter.li.org.
PGP 4208 4D6E 595F 22B9 FF1C ECB6 4A3C 2C54 FE23 53A7
More information about the ubuntu-users
mailing list