| | |
writing variable contents to a specific line in a file
![]() |
Use -i for in-place replacement and do this:
Notice the
Shell Scripting Syntax (Toggle Plain Text)
sk@sk:/tmp$ cat >> file << _EOF_ > line1 > line2 > line3 > line4 > line5 > _EOF_ sk@sk:/tmp$ sed -i '3 s/.*/Your Replacement Here/g' file sk@sk:/tmp$ cat file line1 line2 Your Replacement Here line4 line5 sk@sk:/tmp$
Notice the
sed -i '3 -- the 3 is the line number. •
•
Join Date: Dec 2008
Posts: 63
Reputation:
Solved Threads: 13
•
•
•
•
Use -i for in-place replacement and do this:
Shell Scripting Syntax (Toggle Plain Text)
sk@sk:/tmp$ sed -i '3 s/.*/Your Replacement Here/g' file
Note that the -i option tosedis not standard, and many versions do not have it.
Those that do either require or can take an argument with a backup suffix to save the original file -- a good thing, especially if you are not familiar with usingsed.
Chris F.A. Johnson
http://cfajohnson.com
http://cfajohnson.com
![]() |
Similar Threads
- How to extract a specific line in a text file (Java)
- How to read tab delimited file (Java)
- Reading line from file to act as primary key? (C++)
- Deleting a line from a file (PHP)
- Read a specific line from a text file - how to ? (Java)
- read each line of file (C)
- Reading specific line in a file. / Searching (C++)
Other Threads in the Shell Scripting Forum
- Previous Thread: Grep : Trying to match a trailing backslash (\)
- Next Thread: A shell script that will simulate food ordering system in a restaurant
| Thread Tools | Search this Thread |






