Append to last line of file
|
Original Message
|
Name: Atif Zareef
Date: June 25, 2003 at 06:09:19 Pacific
Subject: Append to last line of file OS: Linux 8.0 CPU/Ram: 512
|
Comment: Hi,
Can someone tell me how to append some text to the last line. Basically i have a last line of a file as follows user1:password i would like to append ':systemuser' to the last line of this file as follows user1:password:systemuser I have tried doing this with cat but cat adds a new line in the end which i do not want ! Thanks in advance
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: James Boothe
Date: June 25, 2003 at 07:13:59 Pacific
Subject: Append to last line of file |
Reply: (edit)Shell commands can append to a file, but that would be AFTER that last newline character. You are wanting to modify the last line, so you need to output a new file, such as: sed '$s/$/:systemuser/' infile > outfile
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Atif Zareef
Date: June 25, 2003 at 07:35:27 Pacific
Subject: Append to last line of file
|
Reply: (edit) James, Thanks for the help !! ..
i had also tried sed but was missing the '$' sign to concat at the end of line
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: susrinu
Date: June 30, 2003 at 09:29:12 Pacific
Subject: Append to last line of file
|
Reply: (edit)How can i append a new line charater at the end of file. Thanks Sri
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: James Boothe
Date: July 1, 2003 at 06:34:16 Pacific
Subject: Append to last line of file |
Reply: (edit)echo >> myfile If the last line of myfile was properly terminated with a newline character, the above will add an additional empty line. If the last line of myfile was "incomplete" (not terminated by a newline character), the above will add the newline character to it, thus completing that line.
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: