The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add new lines with a space in beginning Aejaz UNIX for Advanced & Expert Users 8 05-01-2008 09:21 AM
Delete lines that contain 3 or more words? revax Shell Programming and Scripting 5 12-11-2007 02:33 PM
Adding a character in the beginning of every line in a .dat file Cool Coder Shell Programming and Scripting 2 12-22-2005 02:47 AM
grep - to exclude lines beginning with pattern frustrated1 Shell Programming and Scripting 2 08-29-2005 04:18 AM
delete lines from file2 beginning w/file1 michieka Shell Programming and Scripting 13 06-24-2003 10:42 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Feb 2007
Posts: 36
Stumble this Post!
Adding words to beginning of lines

I have a file that contains a great number of lines, let's say 183 lines, and I want to add: echo " to the beginning of each line. What is the easiest way to do it?

Tx
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Feb 2008
Location: The Netherlands
Posts: 38
Stumble this Post!
I would use sed for that purpose, remember to escape the "
Reply With Quote
  #3 (permalink)  
Old 04-03-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 248
Stumble this Post!
Code:
 awk '{print "echo \""$0}' infile
or

Code:
 sed 's/^/echo "/' infile
Reply With Quote
  #4 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Jun 2006
Posts: 159
Stumble this Post!
Quote:
Originally Posted by Ernst View Post
I have a file that contains a great number of lines, let's say 183 lines, and I want to add: echo " to the beginning of each line. What is the easiest way to do it?

Tx

Code:
cat filename.txt  | perl -ne 'print "echo " . $_' > output.txt
Reply With Quote
  #5 (permalink)  
Old 04-03-2008
Moderator
 

Join Date: Feb 2007
Posts: 1,953
Stumble this Post!
Another one:

Code:
sed 's/.*/echo "&"/' file
Regards
Reply With Quote
  #6 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Feb 2007
Posts: 36
Stumble this Post!
Thanks!

This command works: sed 's/.*/echo "&"/'

What if I want at the same time to add something to the end of each line.
i.e echo "unixtest=test" >> firsttest

what would the command be to add the >> firsttest to teh end of each line
Reply With Quote
  #7 (permalink)  
Old 04-03-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 541
Stumble this Post!
Code:
sed 's/.*$/& >> firsttest/' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0