LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Put .(dot) infront of thousands of entries in a file. (http://www.linuxquestions.org/questions/programming-9/put-dot-infront-of-thousands-of-entries-in-a-file-931707/)

Satyaveer Arya 02-28-2012 05:05 AM

Put .(dot) infront of thousands of entries in a file.
 
Hi,

I have to put dot(.) infront of thousands of entries in a file. Can anyone please tell me how to do that through shell scripting? I have a file named 'restricted', there are more than 70,000 lines or entries in this file and infront of each lines or entries I have to put dot(.). How can I do that? I'm not good in shell scripting, please help me.

firstfire 02-28-2012 05:21 AM

Hi.

Using sed:
Code:

$ sed 's/^/./' infile
(use -i flag to actually change infile or redirect to another file)
or in bash
Code:

while read line; do echo ".$line" ; done <  infile
or using awk (mawk is faster)
Code:

mawk '{print "."$0}' infile
or perl
Code:

perl -ne 'print ".$_"' infile
(again, add -i to edit infile in place)

If you already have each line of a file in a variable, you can use something like this
Code:

$ x=123; echo ${x/#/.}
.123


Satyaveer Arya 02-28-2012 06:29 AM

Hi,

I used this:

Quote:

while read line; do echo ".$line" ; done < infile > a.txt
and it worked for me.

Thanks for your help. :)


All times are GMT -5. The time now is 11:01 PM.