LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-05-2010, 06:11 PM   #1
robotrock
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Rep: Reputation: 0
Question insert tab at beginning of each line in file - and other sed questions


Hello all,

Firstly, I've searched at length and can't seem to find the info so I decided to join this community and ask away. If this is a question that has been answered a billion times please point me in the right direction.

I am trying to create a shell script where a user can specify a file with a list of logins and the script will create a batch file with specific information in specific columns.

Example:

loginfile.txt has

User1
User2
User3

I need the output to be as below:

1 User1 Date 12/31/9999
2 User2 Date 12/31/9999
3 User3 Date 12/31/9999

Where the columns are separated as below.

1[tab][tab]User1[tab]date +%D[tab]12/31/9999
2[tab][tab]User2[tab]date +%D[tab]12/31/9999
3[tab][tab]User3[tab]date +%D[tab]12/31/9999

I can use the nl utility to get the numbers easily enough, but I need two tab separations between the number and the user list. Is there a sed command that will insert at the beginning of each line? If so I can just run nl after I get some tabs up in the front.

Any assistance is appreciated.
 
Old 08-05-2010, 06:19 PM   #2
Meson
Member
 
Registered: Oct 2007
Distribution: Arch x86_64
Posts: 606

Rep: Reputation: 66
Code:
sed -i 's/^/\t\t/' <filename>
 
Old 08-05-2010, 06:27 PM   #3
robotrock
LQ Newbie
 
Registered: Aug 2010
Posts: 2

Original Poster
Rep: Reputation: 0
well that was simple!...I feel silly now.

Thanks very much Meson!
 
  


Reply

Tags
sed


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
sed insert # at the beginning of a line ilo Linux - Newbie 17 12-19-2012 08:21 AM
Insert a line in the test file with sed say_hi_ravi Programming 16 07-16-2010 10:24 AM
How do I insert a line/value after a particular line, in file with sed Glenn D. Programming 3 01-21-2010 09:14 PM
using sed to insert line into file and overwrite the current file jadeddog Programming 3 06-11-2009 07:14 PM
sed command to insert tab? iluvatar Linux - Software 4 06-29-2004 01:56 AM


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

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