![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| see a specific line in file | zivsegal | UNIX for Dummies Questions & Answers | 7 | 04-23-2009 07:08 PM |
| how do I filter for a specific line in a file? | gelitini | UNIX for Dummies Questions & Answers | 5 | 06-26-2008 04:26 PM |
| grep on specific line of the file | rider29 | Shell Programming and Scripting | 4 | 05-29-2008 09:57 AM |
| How to change a specific character in a file | sdubey | Shell Programming and Scripting | 6 | 02-22-2008 03:30 PM |
| Add a line to a specific spot in a file | d__browne | UNIX for Advanced & Expert Users | 6 | 12-07-2006 07:52 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Change Specific Line of a File
Hi everyone,
I am attempting to do something that should be very simple. How do I replace a specific line of a file with different text, and then save that file to its original name? I believe I want to use the sed command with the c option, but I after trying many times, I can't get the right syntax. I am using bash. Mike |
|
||||
|
Works here, Ubuntu 7.something, bash 3.2.13. The sed version is what decides whether it works or not, though. I have GNU sed version 4.1.5
Code:
vnix$ sed '4c\'"I am the walrus" /etc/motd Linux left 2.6.20-17-386 #2 Thu Jul 10 00:02:05 UTC 2008 i686 The programs included with the Ubuntu system are free software; I am the walrus individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Code:
sed '42c\ I am the walrus' file >newfile Last edited by era; 08-18-2008 at 06:10 PM.. |
|
||||
|
Perhaps i am not going about this correctly. Here is my "test file":
$cat test.txt coo coo ca choo $ Let's say I simply want to replace the first line (coo) with koo. With the above suggestion: $sed '1c\'"koo" test.txt sed: 1: "1c\koo": extra characters after \ at the end of c command Putting a space before "koo" yields: $sed '1c\' "koo" test.txt sed: koo: No such file or directory coo ca choo I get closer by typing: $sed '1c\ > koo' test.txt koocoo ca choo But it's still not right. I am using the bash that comes with OS X Leopard. Any ideas on what's going wrong? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|