Preserving Empty Lines while Replacing Numbers


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Preserving Empty Lines while Replacing Numbers
# 1  
Old 05-28-2010
Preserving Empty Lines while Replacing Numbers

Greetings,

I am using tcsh to write a script that will replace the numbers in a file with a single number, the caveat is that this file has blank lines which are necessary for another step down the line so I need to preserve the blank lines. I have tried sed and awk but both will collapse the blank lines or write the replacing number over blank lines. Here is an example:

File1.............File2................Finish Product
1..................(blank).............1
(blank)...........2....................0
3..................(blank).............1
(blank)...........4....................0
etc.................etc.................etc.

The finish product is what I would like to have, but I don't need to get to that point right away, unless you can help provide an easy method. All I need it for the numbers in File1 to be replace by 1's and preserve line order and the same for file 2, but replaced by 0's.

Thanks for any help or guidance you could provide.
# 2  
Old 05-28-2010
Please paste a sample I/P file content and the expected O/P.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question