Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Tip to remove line endings and spaces on a pre-formatted text file? Post 303041486 by newbie_01 on Monday 25th of November 2019 03:24:33 PM
Old 11-25-2019
Tip to remove line endings and spaces on a pre-formatted text file?

Hi,

At the moment, using Notepad++ to do a search and replace, manually section by section which is real painful. Yeah, so copying each section of the line of text and putting into a file and then search and replace, need at least 3-operations in Notepad++.

Here's hoping I will be able to get some help on how to do this via some script or sed/awk combination maybe?

Basically, I have an Oracle tnsnames,.ora file that contains several section of text like below. So, there will be lots of the following, I just listed two of them at the moment.

Code:
test123.abcde.com.ny =
 (DESCRIPTION=
   (LOAD_BALANCE=off)(CONNECT_TIMEOUT=10)(TRANSPORT_CONNECT_TIMEOUT=6)
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1.abcde.com.ny)(PORT=1521)))
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan2.abcde.com.ny)(PORT=1521)))
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dca.abcde.com.ny)(PORT=1521)))
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dcb.abcde.com.ny)(PORT=1521)))
   (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=abcq1_app.abcde.com.ny))
 )
test124.abcde.com.ny =
 (DESCRIPTION=
   (LOAD_BALANCE=off)(CONNECT_TIMEOUT=10)(TRANSPORT_CONNECT_TIMEOUT=6)
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1.abcde.com.ny)(PORT=1521)))
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan2.abcde.com.ny)(PORT=1521)))
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dca.abcde.com.ny)(PORT=1521)))
   (ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dcb.abcde.com.ny)(PORT=1521)))
   (CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=abcq1_app.abcde.com.ny))
 )

I need to convert it to so that it rids itself of the spaces and line endings so that it now looks as below:


Code:
test123.abcde.com.ny =
(DESCRIPTION=(LOAD_BALANCE=off)(CONNECT_TIMEOUT=10)(TRANSPORT_CONNECT_TIMEOUT=6)(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1.abcde.com.ny)(PORT=1521)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan2.abcde.com.ny)(PORT=1521)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dca.abcde.com.ny)(PORT=1521)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dcb.abcde.com.ny)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=abcq1_app.abcde.com.ny)))
test124.abcde.com.ny =
(DESCRIPTION=(LOAD_BALANCE=off)(CONNECT_TIMEOUT=10)(TRANSPORT_CONNECT_TIMEOUT=6)(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1.abcde.com.ny)(PORT=1521)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan2.abcde.com.ny)(PORT=1521)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dca.abcde.com.ny)(PORT=1521)))(ADDRESS_LIST=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=abcq1-scan1-dcb.abcde.com.ny)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=abcq1_app.abcde.com.ny)))

Please advise. Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to remove FIRST Line of huge text file on Solaris

i need help..!!!! i have one big text file estimate data file size 50 - 100GB with 70 Mega Rows. on OS SUN Solaris version 8 How i can remove first line of the text file. Please suggest me for solutions. Thank you very much in advance:) (5 Replies)
Discussion started by: madoatz
5 Replies

2. Shell Programming and Scripting

Adding specific text and spaces to each line in a text file

Hi, I wanted to add specific text to each row in a text file containing three rows. Example: 0 8 7 6 5 5 7 8 9 0 7 9 7 8 9 0 1 2 And I want to add a 21 at the beginning of the first row, and blank spaces at the beginning of the second two rows. To get this: 21 0 8 7 6 5 5 7 8... (4 Replies)
Discussion started by: hertingm
4 Replies

3. Shell Programming and Scripting

Remove spaces from first field, and write entire contents into other text file

Hi all, I have searched and found various threads about removing spaces from a field within a text file. Unfortunately, I have not found exactly what I'm looking for, nor am I adept enough to modify what I've found into what I need. I use the following command to remove the first line... (3 Replies)
Discussion started by: carriehoff
3 Replies

4. Shell Programming and Scripting

Remove blank spaces in a text file...

Hi, I have this problem that there are blank spaces in my text file... i want to remove them line 1 line 2 line 3 I want to remove the space between line 2 and line 3... I tried sed... it work but it prints the whole text file at the command prompt which i dont want.... sde i tried was... (4 Replies)
Discussion started by: bhagya2340
4 Replies

5. Shell Programming and Scripting

Need to remove improperly formatted fortran output line from files, tried sed

I have been trying to remove some improperly formatted lines of output from fortran code I have been using. The problem is that I have some singularities in the math for some points that causes an incorrectly large value to be reported that exceeds the normal formating set in the code resulting in... (2 Replies)
Discussion started by: gillesc_mac
2 Replies

6. Shell Programming and Scripting

sed to remove 1st two characters every line of text file

what is the sed command to remove the first two characters of every line of a text file? each line of the text file has the same amount of characters, and they are ALL NUMERIC. there are hundreds of lines though. for example, >cat file1.txt 10081551 10081599 10082234 10082259 20081134... (20 Replies)
Discussion started by: ajp7701
20 Replies

7. Shell Programming and Scripting

How to remove blank line from a text file?

Hi All, I am creating a text file using perl. The first record I am writing as "$line" and all the other as "\n$line". At the end the file is having N number of lines. I am using this file for MLOAD (Teradata), which is reading N+1 lines in the file and failing.I am not able to find new line... (2 Replies)
Discussion started by: unankix
2 Replies

8. Shell Programming and Scripting

How Select numbers from a line of text, and remove leading spaces?

I have a text file with a line of text that contains numbers and text formatted into groups. I need to extract the number that can be either 1,2 or 3 digits long. Then write it to a variable, but i need to remove any leading spaces in the number first. I can get the numbers out but how to remove... (12 Replies)
Discussion started by: kcpoole
12 Replies

9. UNIX Desktop Questions & Answers

To remove the extra spaces at the end of each line in a file

I have a file of about 10k records and eace line is having an extra space of 5 byte at the end.. Iwant to remove the extra spaces at the end of each line.. Can someone please help me out.. I tried using sed command and its not working... can someone please help me out. (3 Replies)
Discussion started by: rammohan
3 Replies

10. Shell Programming and Scripting

How to remove spaces on a line?

Hi, suppose I have the following data: albert music=top40 age=20 bob music=punk rock age=25 candy music=r n b age=22 dave music=mozart or bach only age=30 I want to extract and manipulate the music column but it's got spaces in it. How can I substitute the space with an underscore... (2 Replies)
Discussion started by: almonds
2 Replies
SUBSTR_COMPARE(3)							 1							 SUBSTR_COMPARE(3)

substr_compare - Binary safe comparison of two strings from an offset, up to length characters

SYNOPSIS
int substr_compare (string $main_str, string $str, int $offset, [int $length], [bool $case_insensitivity = false]) DESCRIPTION
substr_compare(3) compares $main_str from position $offset with $str up to $length characters. PARAMETERS
o $main_str - The main string being compared. o $str - The secondary string being compared. o $offset - The start position for the comparison. If negative, it starts counting from the end of the string. o $length - The length of the comparison. The default value is the largest of the length of the $str compared to the length of $main_str less the $offset. o $case_insensitivity - If $case_insensitivity is TRUE, comparison is case insensitive. RETURN VALUES
Returns < 0 if $main_str from position $offset is less than $str, > 0 if it is greater than $str, and 0 if they are equal. If $offset is equal to or greater than the length of $main_str, or the $length is set and is less than 1 (prior to PHP 5.6), substr_compare(3) prints a warning and returns FALSE. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.6.0 | | | | | | | $length may now be 0. | | | | | 5.1.0 | | | | | | | Added the possibility to use a negative $offset. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 A substr_compare(3) example <?php echo substr_compare("abcde", "bc", 1, 2); // 0 echo substr_compare("abcde", "de", -2, 2); // 0 echo substr_compare("abcde", "bcg", 1, 2); // 0 echo substr_compare("abcde", "BC", 1, 2, true); // 0 echo substr_compare("abcde", "bc", 1, 3); // 1 echo substr_compare("abcde", "cd", 1, 2); // -1 echo substr_compare("abcde", "abc", 5, 1); // warning ?> SEE ALSO
strncmp(3). PHP Documentation Group SUBSTR_COMPARE(3)
All times are GMT -4. The time now is 06:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy