Sponsored Content
Top Forums Shell Programming and Scripting deleting blank lines ONLY at the end of the file Post 302517708 by devrymike on Wednesday 27th of April 2011 01:46:20 PM
Old 04-27-2011
Is this just for a single file? If so, probably what you're going to want to do is count either characters or lines and start deleting blank lines after that.

If it's for multiple files, can you give some example data?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Blank Lines - End of file

Hi all I need to strip blank lines from the end of a file. I have searched and found topics on how to strip lines from the entirety of a file - however I need to limit this to only the last 3-4 lines. Any ideas? Thanks (4 Replies)
Discussion started by: saabir
4 Replies

2. Shell Programming and Scripting

Deleting the blank line in a file and counting the characters....

Hi, I am trying to do two things in my script. I will really appreciate any help in this regards. Is there a way to delete a last line from a pipe delimited flat file if the last line is blank. If the line is not blank then do nothing..... Is there a way to count a word that are starting... (4 Replies)
Discussion started by: rkumar28
4 Replies

3. Shell Programming and Scripting

Delete blank lines at the end of file

I am attempting to delete blank lines in my file and I've used this command: sed '/^$/d' $file > $file.fixed all this seems to do is copy the file and not delete the blank lines located at the end of the file. Any assistance would be greatly appreciated. (3 Replies)
Discussion started by: TL56
3 Replies

4. Shell Programming and Scripting

deleting the lines at the end of the file.

I have a text file with two coulmn first column is just used in to show the line number, these line number are not there in the real file. I want to delete the line 16(in this file) here, even tough there is no data inside it . this empty line is causing me a problem by throwing me garbage... (12 Replies)
Discussion started by: shashi792
12 Replies

5. UNIX for Dummies Questions & Answers

Add blank line to end of file

Alright, so I was looking around a bit on the forum before posting and still don't really understand so I figured I'd post my own question. I am appending two files using cat file_1.txt >> file_2.txt The problem is that I need a blank line in between the two different text files and it does... (2 Replies)
Discussion started by: cgagnon
2 Replies

6. Shell Programming and Scripting

Perl : blank lines are displayed in the output after deleting few rows from excel

I am working on an assignment to pull all the records from excel sheet programatically and use the data for further calculations. In this process, I first defined 10 records in excel sheet and executed the below code. In the first run it is OK. But after deleting last few rows in excel sheet and... (0 Replies)
Discussion started by: giridhar276
0 Replies

7. Shell Programming and Scripting

Issue deleting blank line from a file

I'm trying to delete the blank lines from the file $Sfile. tried the below set of commands. Both are giving the same error (: bad interpreter: No such file or directory) awk 'NF > 0' $Sfile > $Tfile cat $Tfile sed -i '/^$/d' $Sfile cat $Sfile Not sure if there's any other problem with... (17 Replies)
Discussion started by: Pandee
17 Replies

8. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

9. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

10. UNIX for Beginners Questions & Answers

Deleting the last non blank line from a file

PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17... (6 Replies)
Discussion started by: swathi reddy1
6 Replies
nl(1)							      General Commands Manual							     nl(1)

NAME
nl - Numbers lines in a file SYNOPSIS
nl [-b type] [-d delimiter1[delimiter2]] [-f type] [-h type] [-i number] [-l number] [-n format] [-p] [-s [separator]] [-vnumber] [-wnum- ber] [file] STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: nl: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
Use the following options to change the default settings. Specifies which body section lines to number. The recognized types are as fol- lows: Numbers all lines. Number only non-empty lines. Does not number any lines. Numbers only those lines containing the specified pat- tern. The full range of regular expressions is supported for pattern. The default for type is t. Uses delimiter1 and delimiter2 as the delimiters for the start of a logical page section. The default characters are : (backslash followed by a colon). You can specify either one or two characters after the -d option. If you want to use a backslash as a delimiter, enter two back- slashes (\). If you specify only one character, it is used as start of a logical page, and the end delimiter remains the default. Specifies which logical page footer lines to number. The types recognized are the same as in -b type. The default for type is n. Specifies which logical page header lines to number. The types recognized are the same as in -b type. The default for type is n. Increments logical page line numbers by number. The default is 1. Counts number blank lines as 1. You must use one or more of the "-ba", "-fa", and "-ha" options with this option for it to be effective. For example, -l3 will only number the third adjacent blank. The default is 1. Specifies format as the line numbering format. Recognized formats are as fol- lows: Left justified, leading zeroes are suppressed. Right justified, leading zeroes are suppressed (default). Right justified, leading zeroes are kept. Ignores logical page delimiters (does not restart numbering). Separates text from line numbers with the separator string. The default value of separator is a tab character. [Tru64 UNIX] If you enter -s without an argument, there is no separation between the line number and its text. Sets the initial logical page line number to number. Specifies number as the number of digits in the line number. The default value of number is 6. OPERANDS
The path name of a file in which the lines are to be numbered. If file is not specified, standard input is used. DESCRIPTION
The nl command reads file (standard input by default), numbers the lines in the input, and writes the numbered lines to standard output. In the output, nl numbers the lines on the left, according to the options you specify on the command line. The input text must be written in logical pages. Each logical page has a header, a body, and a footer section (sections can be empty). Unless you use the -p option, nl resets the line numbers at the start of each logical page. You can set line numbering options indepen- dently for the header, body, and footer sections (for example, no numbering of header and footer lines while numbering text lines only in the body). Signal the start of logical page sections with lines in file that contain nothing but the following delimiter characters (assuming the default delimiters--see the description of the -d option): Line Contents Start of ::: Header :: Body : Footer You can name only one file on the command line. You can list the options and the file name in any order. EXIT STATUS
The following exit values are returned: Successful completion. An error occurred. EXAMPLES
To number only the nonblank lines, enter: nl chap1 This displays a numbered listing of chap1, numbering only the nonblank lines in the body sections. If chap1 contains no :: :, : :, or : delimiters, then the entire file is considered the body. To number all lines, enter: nl -ba chap1 This numbers all the lines in the body sections, including blank lines. This form of the nl command is adequate for most uses. To specify a different line number format, enter: nl -i10 -nrz -s:: -v10 -w4 chap1 This numbers the lines of chap1, starting with 10 (-v10) and counting by 10s (-i10). It displays four digits for each number (-w4), including leading zeroes (-nrz). The line numbers are separated from the text by two colons (-s::). For example, if chap1 contains the following text: A not-so-important note to remember: You can't kill time without injuring eternity. then the numbered listing is as follows: 0010::A not-so-important note to remember: 0020::You can't kill time without injuring eternity. Notice that the blank line was not numbered. To do this, use the -ba option as shown in Example 2. ENVIRONMENT VARIABLES
The following environment variables affect the execution of nl: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization vari- ables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments and input files), the behavior of classes within regular expressions, and for deciding which characters are in character class graph. Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MES- SAGES. SEE ALSO
Commands: cat(1), pr(1) Standards: standards(5) nl(1)
All times are GMT -4. The time now is 06:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy