Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

overwrite specific lines in a file

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-09-2008   -   Original Discussion by csecnarf
csecnarf's Unix or Linux Image
csecnarf csecnarf is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 14 August 2008, 9:50 AM EDT
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
overwrite specific lines in a file

Hi all,

I am trying to overwrite some lines of a very big file.
I know the number of the line but I don't know how to point the cursor on its beginning. there is an option to notice the offset in lines?

thanks!
Sponsored Links
    #2  
Old Unix and Linux 05-09-2008   -   Original Discussion by csecnarf
jim mcnamara's Unix or Linux Image
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 13 December 2017, 6:33 PM EST
Location: NM
Posts: 11,249
Thanks: 577
Thanked 1,121 Times in 1,033 Posts
Are you in an editor?
for vi <esc>20204G takes you to line 20204

Or do you want to replace line #x with text using another tool?
Sponsored Links
    #3  
Old Unix and Linux 05-09-2008   -   Original Discussion by csecnarf
csecnarf's Unix or Linux Image
csecnarf csecnarf is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 14 August 2008, 9:50 AM EDT
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
no, I want to do it in a boot script.

I want to do it by commands lines.
    #4  
Old Unix and Linux 05-09-2008   -   Original Discussion by csecnarf
danmero's Unix or Linux Image
danmero danmero is offline Forum Advisor  
 
Join Date: Nov 2007
Last Activity: 31 July 2016, 9:42 AM EDT
Location: H3X
Posts: 2,163
Thanks: 11
Thanked 123 Times in 116 Posts
For large files sed it's the best tool.
Sponsored Links
    #5  
Old Unix and Linux 05-10-2008   -   Original Discussion by csecnarf
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline
Registered User
 
Join Date: Dec 2003
Last Activity: 12 June 2016, 11:03 PM EDT
Location: /dev/ph
Posts: 4,996
Thanks: 73
Thanked 475 Times in 437 Posts
The ed(1) utility is typically used for such tasks.
Sponsored Links
    #6  
Old Unix and Linux 05-10-2008   -   Original Discussion by csecnarf
csecnarf's Unix or Linux Image
csecnarf csecnarf is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 14 August 2008, 9:50 AM EDT
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Ok I have used it, but I think that my manner is not really elegant.

Do you know how to (by sed)...

overwrite a line which actually you only know how it begins but not how finishes?

I want to change a settings file... so I want to do something like that.

sed '49s/HorizSync[...]/HorizSync 30.0 - 83.0/g' xorg.conf

where [...] are characters which I don't know.

Thanks a lot!!
Sponsored Links
    #7  
Old Unix and Linux 05-10-2008   -   Original Discussion by csecnarf
Franklin52's Unix or Linux Image
Franklin52 Franklin52 is offline
Registered User
 
Join Date: Feb 2007
Last Activity: 5 December 2017, 5:22 PM EST
Location: The Netherlands
Posts: 7,746
Thanks: 139
Thanked 558 Times in 520 Posts

Code:
 sed 's/^HorizSync.*/HorizSync 30.0 - 83.0/g' file

Regards
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extracting specific lines of data from a file and related lines of data based on a grep value range? Wynner Shell Programming and Scripting 3 05-18-2011 12:35 PM
Substitute specific lines with lines from another file rahmathulla Shell Programming and Scripting 1 01-11-2009 11:45 AM
shell overwrite lines in a file ACTGADE UNIX Desktop Questions & Answers 4 10-28-2008 08:47 AM
how to display specific lines of a specific file raidkridley UNIX for Dummies Questions & Answers 2 10-15-2008 03:46 PM
How do you specific lines in a file? hedgehog001 UNIX for Dummies Questions & Answers 2 08-23-2005 01:04 AM



All times are GMT -4. The time now is 10:12 PM.