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
how to insert a extra line in a text file bhaviknp Shell Programming and Scripting 2 03-07-2008 08:38 AM
Insert text file at a certain line. insania Shell Programming and Scripting 4 08-01-2006 02:46 AM
insert word in each line of a file atticus Shell Programming and Scripting 7 03-23-2006 02:15 AM
Failed to insert string into file before line nir_s Shell Programming and Scripting 7 07-26-2005 01:37 AM
Insert a line as the first line into a very huge file shriek UNIX for Advanced & Expert Users 3 03-09-2005 01:22 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 06-21-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Question insert a line in a file

Hello guys,

Need to know how to insert a line at top of the file, without using temp files.
Can we do it on the fly?

Regards,
Rishi
  #2 (permalink)  
Old 06-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Code:
/bin/echo '1i\nNew Line Goes Here\n.\nwq' | ex -s myFile.txt
  #3 (permalink)  
Old 06-21-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
The script does not seem to be working...
  #4 (permalink)  
Old 06-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
Quote:
Originally Posted by RishiPahuja
The script does not seem to be working...
thanks for sharing.
what's taking place?
  #5 (permalink)  
Old 06-21-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Question

as per ur format it works ok... but when i tried with this version

ex -s myfile < EOF
1i
New Line Goes Here
.
wq
EOF

it is not able to process it...any clues?

Thanks,
Rishi
  #6 (permalink)  
Old 06-21-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
ex -s myfile <<EOF
  #7 (permalink)  
Old 06-21-2005
pixelbeat pixelbeat is offline
Registered User
  
 

Join Date: Jun 2005
Location: Ireland
Posts: 61
here documents require << not < I think.
Generally I think it easier to read

Code:
echo "
1i
New Line Goes Here
.
wq
" | ex -s myfile
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 03:53 PM.


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