LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-28-2012, 04:05 AM   #1
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Dehradun, Uttarakhand, India
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,412

Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
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.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-28-2012, 04:21 AM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 615

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
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

Last edited by firstfire; 02-28-2012 at 04:35 AM.
 
3 members found this post helpful.
Old 02-28-2012, 05:29 AM   #3
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Dehradun, Uttarakhand, India
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,412

Original Poster
Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
Hi,

I used this:

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

Thanks for your help.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Firewall infront of router setup? tjwilliams Linux - Security 1 03-10-2011 07:06 PM
how to hide a file using file permissions in linux without using dot davender84 Linux - General 4 03-26-2009 12:13 AM
Thousands of "unattached inode" entries freezing fsck. Nothsa Linux - General 4 05-11-2008 04:56 PM
where to put routing entries jbako Linux - Networking 3 05-23-2005 07:14 AM
what entries to put into fstab for new hard disk? chuck_notorious Linux - Hardware 1 04-21-2004 03:37 AM


All times are GMT -5. The time now is 06:28 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration