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
search and replace a specific text in text file? santosham UNIX for Dummies Questions & Answers 4 06-25-2008 05:53 PM
How to replace specific text line out of multiple occurance madhusmita Shell Programming and Scripting 5 06-17-2008 01:03 PM
adding text to end of each line in a file cubs0729 Shell Programming and Scripting 2 11-10-2005 01:02 PM
jumping to a specific line in a text file mridula High Level Programming 4 09-20-2005 01:49 AM
Adding Text To each line of a file cubs0729 Shell Programming and Scripting 4 09-08-2005 04:40 PM

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

Join Date: Aug 2008
Posts: 9
Adding specific text and spaces to each line in a text file

Hi,

I wanted to add specific text to each row in a text file containing three rows. Example:

0 8 7 6 5 5
7 8 9 0 7 9
7 8 9 0 1 2

And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this:

21 0 8 7 6 5 5
7 8 9 0 7 9
7 8 9 0 1 2

Thanks in advance!
  #2 (permalink)  
Old 08-25-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,715
This is a clunky sed script to do what you want -
Code:
sed '1s/^/21 /;2s/^/ /;3s/^/ /' filename > newfilename
  #3 (permalink)  
Old 08-25-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,291
With some basic commands:

Code:
echo -n '21 ';cat file > newfile
Regards
  #4 (permalink)  
Old 08-25-2008
TinWalrus TinWalrus is offline
Registered User
  
 

Join Date: May 2007
Posts: 35
using awk

awk '{if ( NR == 1 ){print 21,$0}else{print " " $0}}' name_of_file
  #5 (permalink)  
Old 08-25-2008
hertingm hertingm is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 9
Thanks!
Sponsored Links
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:23 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