Re: Adding to the front of a line
- From: Ray Parrish <crp@xxxxxxx>
- Date: Mon, 19 Jan 2009 19:33:50 -0800
Matthew Flaschen wrote:
Matthew Flaschen wrote:Hello again,
Ray Parrish wrote:
Hello,There are many ways. Here's one:
I've downloaded a text file of the new sites to block to avoid the
conficker worm that is currently infecting Windows users, and would like
to send it to my Windows using friends and family. However the file
unfortunately has only the host names, one per line. I would like to add
the 127.0.0.1 and a space to the front of each line in the file before I
send it out, so all they have to do is copy and paste it's contents to
the end of their hosts files.
while read site; do
echo "$site 127.0.0.1"
done < sites.txt > output_file.txt
Whoops. That was backwards. It should be:
while read site; do
echo "127.0.0.1 $site "
done < sites.txt > output_file.txt
That *almost* worked perfectly, with the exception that it is adding a
blank line between each line in the output file which is undesirable. 8-)
I'm off to the string handling section of my favorite bash scripting
site to learn how to strip the line feed off of the end of $site at the
start of the loop.
Thanks again for the excellent start, and tipping me off to how easy it
is to read in files with a while loop. Here is what I've done so far to
make the code more universally useful to me.
#!/usr/bin/env bash
# Add a text string to the front of each line in a file.
# Command line parameters $1 - file to read in $2 - string to add to
front of line $3 - output filename
#
if [ $1 == "" ] || [ $2 == "" ] || [ $3 == "" ]
then echo "Usage: AddStringtoLineFront.sh InputfileName StringToAdd
OutPutFileName";
else
while read site; do
echo "$2 $site "
done < $1 > $3
fi
exit
Later, Ray Parrish
--
http://www.rayslinks.com/ Web index of human reviewed links.
<http://www.rayslinks.com/Troubleshooting%20and%20fixing%20Windows.html>
Trouble shooting and Fixing Windows
http://www.writingsoftheschizophrenic.com My poetry in web pages
--
ubuntu-users mailing list
ubuntu-users@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
- Follow-Ups:
- Re: Adding to the front of a line
- From: Ray Parrish
- Re: Adding to the front of a line
- From: Cameron Hutchison
- Re: Adding to the front of a line
- From: Matthew Flaschen
- Re: Adding to the front of a line
- From: Smoot Carl-Mitchell
- Re: Adding to the front of a line
- References:
- Adding to the front of a line
- From: Ray Parrish
- Re: Adding to the front of a line
- From: Matthew Flaschen
- Re: Adding to the front of a line
- From: Matthew Flaschen
- Adding to the front of a line
- Prev by Date: Re: Why does my system dim and go grey sometimes?
- Next by Date: Re: Why does my system dim and go grey sometimes?
- Previous by thread: Re: Adding to the front of a line
- Next by thread: Re: Adding to the front of a line
- Index(es):
Relevant Pages
|