Create new strings with sed

December 29, 2010 at 04:42:10
Specs: Windows Vista, 4/g
I have a text file with lines like this:
car
house
boat

and I would like to output a new file with lines such as:
car.mydomain.com
house.mydomain.com
...
and so on.
How can I do this using sed?

thanks


See More: Create new strings with sed

Report •

#1
December 29, 2010 at 06:33:37
I dunno sed but this bat should do.

==========================================
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (myfile) do (
>> newfile echo.%%a.mydomain.com
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
December 29, 2010 at 07:58:35
And if you must use sed:

sed s/$/.mydomain.com/ <inputfile >outputfile


Report •

#3
December 29, 2010 at 08:35:04
Hi klint,

While you're here...

This is based on a post by Judago. The basic purpose is to strip leading zeros. Clearly, it works. But I haven't figured out why. I'm willing to study it more but while you're here, can you comment?

TIA

==============================================
for /f "tokens=* delims=0" %%a in ("00the0string") do echo whatever with %%a
goto :eof


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
December 29, 2010 at 10:03:43
Yes, that's a useful trick. The 0 is treated as a delimiter, and CMD.EXE seems to remove all leading delimiters (but not trailing ones). It's just the same as how you usually do your for /f loops:

for /f "tokens=* delims= " %%a in (....)

When you use this, for example, to list the contents of a file, you will notice that it modifies all lines that begin with spaces. Judago's trick is the same, except it uses 0 instead of space.


Report •

#5
December 29, 2010 at 10:18:58
I think I must use sed because I am on Linux.
klint - that works well. How can I switch the string around - e.g. how can I change it to:

mydomain.com/boat
mydomain.com/house

?


Report •

Ask Question