Sponsored Content
Top Forums Shell Programming and Scripting Preserving Empty Lines while Replacing Numbers Post 302425421 by devtakh on Friday 28th of May 2010 12:02:06 AM
Old 05-28-2010
Please paste a sample I/P file content and the expected O/P.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replacing numbers greater than 0 with 1

I have some ASCII files containing numerous numbers. What I'd like to do is replace all numbers greater than 0 with 1. Examples of the numbers include: - 000011 and 000042 Thanks (4 Replies)
Discussion started by: vrms
4 Replies

2. Shell Programming and Scripting

Need help in finding and replacing port numbers.

Hi All, I am trying to write a shell script which firstly will search some files and then increase the port numbers mentioned in them by a certain no. let me clear it with an example- suppose there r few files a,b,c,d.... file a's content- <serverEntries xmi:id="ServerEntry_1"... (3 Replies)
Discussion started by: ankushsingh10
3 Replies

3. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

4. Shell Programming and Scripting

Replacing numbers in bash scripts

Hi, I have lines in some files that look exactly as below, and the line numbers they occur in are always the same. (Lines 136-139) W 0.00000000 0.00000000 2.00000000 W 0.50000000 0.50000000 2.50000000 W 0.00000000 0.00000000 3.00000000 W 0.50000000 0.50000000 3.50000000 I'd like to... (0 Replies)
Discussion started by: bluesmodular
0 Replies

5. Shell Programming and Scripting

Mapping and replacing numbers in two files

hi i have two files one of the form 1 2 2 45 3 56 4 98 5 6598 6 98 7 10 8 0 9 15 10 56 This file's significance is that it maps the number in first column to that of the number in second column The other file is of the form 1 2 (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

6. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing them with blank lines

So the tag for this forum says all newbies welcome... All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed. Here's what I did come up with though: ... (2 Replies)
Discussion started by: Golpette
2 Replies

7. Shell Programming and Scripting

Summing over specific lines and replacing the lines with the sum using sed, awk

Hi friends, This is sed & awk type question. I have a text file which has numbers spread all over the file. I want to sum the series of numbers whenever i find it and produce an output file with the sum. For example ###start of input text file #### abc def ghi 1 2 3 4 kjld random... (3 Replies)
Discussion started by: kaaliakahn
3 Replies

8. Shell Programming and Scripting

Replacing a character between two numbers

Hi, I need to replace a character between two numbers (specifically a - to a _). The problem is that they can be *any* numbers. So, I need a one liner to turn a file like this: 1-2 3-4 55-66 4323-12312893 into the following 1_2 3_4 55_66 4323_12312893 Any help would be appreciated! (5 Replies)
Discussion started by: mikey11415
5 Replies

9. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

10. Shell Programming and Scripting

Edit lines in file preserving part of it

Hello: I have the following HTML table: <table> <thead> <tr> <th>Code</th> <th>Percentage</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>30%</td> </tr> <tr> <td>2</td> ... (3 Replies)
Discussion started by: Cacializ
3 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 08:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy