The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
set EDITOR=vi -> default editor not setting for cron tab aarora_98 Shell Programming and Scripting 6 3 Weeks Ago 11:01 PM
regarding vi editor girish_shukla SCO 3 02-19-2008 03:58 AM
Vi editor jazz High Level Programming 1 11-17-2005 04:37 AM
vi editor eloquent99 UNIX for Dummies Questions & Answers 1 01-14-2003 01:49 AM
Using the vi editor pbsys UNIX for Dummies Questions & Answers 2 11-05-2001 11:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-27-2007
Nafanja's Avatar
Registered User
 

Join Date: Nov 2007
Location: UK
Posts: 9
Stumble this Post!
Which editor to use?

Good day, everyone!
I've started using/learning UNIX recently and the only problem i get, is that I can hardly edit a file from within the script (searching/replacing, extracting, ect.) I've tried vi, ex, ed all of them did only half of job, which means they opened out a file but did not perform any editing or any required operations. Hence, I've got a question:
which editor do i need to use, to be able to perform an editing of a file from the script?

Thank you very much for any suggestions and what's more important explanations
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-27-2007
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
ex/sed/awk are your friends
Reply With Quote
  #3 (permalink)  
Old 11-27-2007
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Stumble this Post!
What type of problem you have encountered with 'vi' ?
Reply With Quote
  #4 (permalink)  
Old 11-27-2007
Nafanja's Avatar
Registered User
 

Join Date: Nov 2007
Location: UK
Posts: 9
Stumble this Post!
Quote:
Originally Posted by bhargav View Post
What type of problem you have encountered with 'vi' ?
The main problem i'm having with vi is, that i understand how to open a file on specific line, the thing I don't get is how to save the changes. For example, I've been trying to do something like this.
Code:
vi +5n myfile
:i 
"Insert some text"
:w
:q
As I said, it only opened editor in Insert mode.
It's probably silly me
I've tried to use sed, and it helped, although that was the code I've found on Internet, but I don't understand completely the meaning of criterias yet.
p.s. I've managed to solve the given example using temp file, which is being an absolutely time and space consuming solution....
Reply With Quote
  #5 (permalink)  
Old 11-28-2007
Registered User
 

Join Date: Nov 2007
Posts: 25
Stumble this Post!
You can simply do whatever you want with test in ed/sed/awk etc.
Notice that, you can edit content of file during reading it and forward output from it to other file and after that simple overwrite it e.g. in awk:
Code:
awk 'some_code' some_file > new_file; mv new_file some_file
Or use ed like it:
Code:
ed file <<-ENDIT
g/nrumber_of_line/a/some_new_text/
w
q
ENDIT
depends from your expectations.
Reply With Quote
  #6 (permalink)  
Old 11-29-2007
Nafanja's Avatar
Registered User
 

Join Date: Nov 2007
Location: UK
Posts: 9
Stumble this Post!
Thank you very much. That's helped a lot!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:25 PM.


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