![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding multiple line at the end of the file | kaibiganmi | Shell Programming and Scripting | 2 | 11-23-2007 12:21 AM |
| adding a line to a file | andy2000 | Shell Programming and Scripting | 2 | 03-26-2007 09:44 AM |
| Adding a character in the beginning of every line in a .dat file | Cool Coder | Shell Programming and Scripting | 2 | 12-22-2005 06:47 AM |
| adding text to end of each line in a file | cubs0729 | Shell Programming and Scripting | 2 | 11-10-2005 01:02 PM |
| Adding Text To each line of a file | cubs0729 | Shell Programming and Scripting | 4 | 09-08-2005 05:40 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Adding new line at the end of file
Hi
I have few files. For some files the cursor is at the end of last line. For other files, cursor is at the new line at the end. I want to bring the cursor down to next line for the files that are having cursor at the end of last line In otherwords, I want to introduce a blank line at the end of line, if it doesn't exist Here is example.. for test_file cusor is at the end of line3. I want to bring the cursor down to the next line. Then only, I can process that file. Please help me. Feel free to ask me if you unable to understand my requirements ***test_file**** line1 line2 line3 line4 Last edited by somesh_p; 11-05-2007 at 03:44 PM.. |
|
||||
|
Yes.. it is working fine for the files that doens't have a blank line at the end of file
But, if the file already contains a blank line at the end, the modified file is becoming zero bytes. It shouldn't modify the file, if it already has blank line at the end Please suggest some thing $ ls -ltr test2.webM -rw-r--r-- 1 spamarth users 15010 Nov 5 16:34 test2.webM $ sed '${/^$/!s/$//;}' test2.webM > ./test2 $ ls -ltr test2.webM test2 -rw-r--r-- 1 spamarth users 15010 Nov 5 16:34 test2.webM -rw-r--r-- 1 spamarth users 0 Nov 5 16:35 test2 $ |
|
|||||
|
Quote:
Code:
sed '${/^$/!s/$/\
/;}' filename
and NOT: Code:
sed '${/^$/!s/$//;}'
It works even on my old Solaris ![]() Code:
$ cat file1
line1
line2
line3
line4
$ cat file2
line1
line2
line3
line4
$ sed '${/^$/!s/$/\
> /;}' file1
line1
line2
line3
line4
$ sed '${/^$/!s/$/\
/;}' file2
line1
line2
line3
line4
$
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|