deleting the lines at the end of the file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting deleting the lines at the end of the file.
# 8  
Old 09-10-2010
Quote:
Originally Posted by shashi792
@Franklin,
I did not understand your question.

I have these problem when i am streaming my text file to a C++ array.

rite now i am manually going to the line 15 and at the end of the line i'm using delete so that the last empty line gets deleted .
I also don't understand your question Smilie, I'm still guessing...maybe this is what you're looking for:
Code:
awk '{printf("%s%s",NL,$0);NL=RS}' file > newfile

# 9  
Old 09-10-2010
in your file if the line always start with a number then try below

Code:
sed  -n '/[0-9]/p' file > newfile

this will give the lines that have numbers in it and all the blank lines should be deleted.. try this....

Last edited by Franklin52; 09-10-2010 at 09:14 AM.. Reason: Please use code tags, thank you!
# 10  
Old 09-10-2010
@ itslee,
Thanks for answering, that was not what i was looking for.

@ franklin,
This is what i wanted exactly, at last found it Smilie, is it possible that i overwrite in the same file instead of using a new file as we use

Code:
sed -i

option
# 11  
Old 09-10-2010
Quote:
Originally Posted by shashi792
@ franklin,
This is what i wanted exactly, at last found it Smilie, is it possible that i overwrite in the same file instead of using a new file as we use

Code:
sed -i

option
awk doesn't have an option to edit files "in place". You can do something like this if the command works fine:
Code:
awk '{printf("%s%s",NL,$0);NL=RS}' file > newfile && mv newfile file

BTW: That's what I meant with delete the last newline character of the file.

Regards
This User Gave Thanks to Franklin52 For This Post:
# 12  
Old 09-14-2010
Did you try this:

Did you try any of this remove any empty lines from the file:

HTML Code:
grep -v "^$" <filename> > newfile
or,

HTML Code:
sed 's/^$/d' <filename> > newfile
# 13  
Old 09-14-2010
Quote:
Originally Posted by momin
Did you try any of this remove any empty lines from the file:

HTML Code:
grep -v "^$" <filename> > newfile
or,

HTML Code:
sed 's/^$/d' <filename> > newfile
As mentioned, the OP wants to remove the newline character after the last line not an empty line.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

deleting the part of the file(overwrite) using start and end point

here is the contents of bigfile.sql CREATE TABLE `Table11` ( `id` int(11) NOT NULL , `entityName` enum('Lines','EndUsers') COLLATE utf8_unicode_ci NOT NULL, `parentAllianceMigrationProjectId` varchar(255) NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=2000 DEFAULT CHARSET=utf8... (30 Replies)
Discussion started by: vivek d r
30 Replies

2. Shell Programming and Scripting

deleting blank lines ONLY at the end of the file

Hi Guys, I have a quetion which was already discussed in the forum, but for some reason all approches suggested fail for me. I have a file which have blank lines at the body of the text as well as at the end. I need to delete ONLY blank lines at the end. Unfortunatly the approach below does not... (5 Replies)
Discussion started by: aoussenko
5 Replies

3. UNIX for Dummies Questions & Answers

deleting word from this point to end of file in VI

Hi All i need to delete a recurring word from point "n" till end of the file. there are other words in this file so i cannot use `dG`, can anyone help me out? Kind regards Brian (4 Replies)
Discussion started by: brian112
4 Replies

4. Shell Programming and Scripting

deleting lines from file

We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Discussion started by: daveisme
8 Replies

5. UNIX for Advanced & Expert Users

Deleting lines from a file

How I can delete 100 lines anywhere in a file without opening a file and without renaming the file. (11 Replies)
Discussion started by: Nirgude07
11 Replies

6. UNIX for Dummies Questions & Answers

Deleting whole lines from a file

I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
Discussion started by: red baron
3 Replies

7. UNIX for Advanced & Expert Users

Deleting end of line $ character in file

Hi, I've got a file where in the middle of the record is a $ end of line character, visible only when I open the file in vi and do :set list. How to I get rid of the character in the middle and keep it at the end. The middle $ character always appears after SW, so that can be used to tag it.... (3 Replies)
Discussion started by: bwrynz1
3 Replies

8. UNIX Desktop Questions & Answers

Deleting Junks at the end of each line in a file

Is there any way to delete the Junk Characters(Invalid Characters like ^,',",),(,&,# etc.,) at the end of each record in a file? I want to do this using a single line script. Thanks to all in advance!!! (5 Replies)
Discussion started by: dave_nithis
5 Replies

9. Shell Programming and Scripting

Deleting lines in a file

How do I delete all the lines after the line containing text ***DISCLOSURES*** . I want to delete this line too. Thank you (2 Replies)
Discussion started by: reachsamir
2 Replies

10. Shell Programming and Scripting

Deleting end line spaces for along file

How can i clear all space characteres for a long file at the end of each line? (3 Replies)
Discussion started by: osymad
3 Replies
Login or Register to Ask a Question