The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding specific text and spaces to each line in a text file hertingm Shell Programming and Scripting 4 08-25-2008 02:34 PM
Insert a line in a text file 4scriptmoni Shell Programming and Scripting 10 08-04-2008 10:17 AM
how to insert a extra line in a text file bhaviknp Shell Programming and Scripting 2 03-07-2008 08:38 AM
How to insert text into first line of the file and middle of the file? ali hussain Shell Programming and Scripting 3 03-05-2007 05:54 AM
Insert text file at a certain line. insania Shell Programming and Scripting 4 08-01-2006 02:46 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-30-2008
Muhammad Afzal Muhammad Afzal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 2
Unhappy How to insert some constant text at beginig of each line within a text file.

Dear Folks ,

I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp.
I can do this in vi editor by using this command :g/^/s//BBB_

e,g I have a file named as Test.dat and it containins below text:

michal
David
Lisa
Antonio

Now I want to insert BBB at the beging of every line and out put should look like belwo:

BBB_michal
BBB_David
BBB_Lisa
BBB_Antonio

Is there are way by using sed, awk or any other command I can get the above out put file. I want to run this command at UNIX command prompt.

Please advice & your feed back is highly appreciated.

Many thanks

Kind Regards

M.Afzal
  #2 (permalink)  
Old 10-30-2008
paresh n doshi paresh n doshi is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 38
yes, if your file is line sequential file
you can use awk
awk ' { print "BBB_" $0 } ' yourfilename > outputfilename
  #3 (permalink)  
Old 10-30-2008
Muhammad Afzal Muhammad Afzal is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 2
Dear Paresh,

You command works very fine, its perfect and you are really intelligent.

Many thanks,

Kind Regards,

Muhammad Afzal
  #4 (permalink)  
Old 10-30-2008
DeCoTwc DeCoTwc is offline
Registered User
  
 

Join Date: Mar 2008
Location: NYC
Posts: 74
Alternative...

Code:
(04:35:36\[ddeco***@S.ManDNCS)
[~]$ cat test
michal
David
Lisa
Antonio

(04:35:36\[ddeco***@S.ManDNCS)
[~]$  sed 's/^/BBB_/g' test
BBB_michal
BBB_David
BBB_Lisa
BBB_Antonio
PS: Whats up fellow (former) DTVer
  #5 (permalink)  
Old 10-30-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
Code:
sed 's/^/BBC_/' file
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0