Removing empty lines(space) between two lines containing strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Removing empty lines(space) between two lines containing strings
# 1  
Old 06-02-2009
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 "BAP_BSC6/07B/00" 418 090529 1059
RXOCF-150 GDP002 2

DOOR OPEN
A2/EXT "BAP_BSC6/07B/00" 874 090529 1346
RXOCF-401 BBN001 2

SITE ON BATTERY

Output File :
A1/EXT "BAP_BSC6/07B/00" 844 090602 1605
RXOCF-465 PDTR11
SITE ON BATTERY
A2/EXT "BAP_BSC6/07B/00" 418 090529 1059
RXOCF-150 GDP002 2
DOOR OPEN
A2/EXT "BAP_BSC6/07B/00" 874 090529 1346
RXOCF-401 BBN001 2
SITE ON BATTERY
# 2  
Old 06-02-2009
try to show some code next time.
Code:
# awk '!/^$/' file
A1/EXT "BAP_BSC6/07B/00" 844 090602 1605
RXOCF-465 PDTR11 1
SITE ON BATTERY
A2/EXT "BAP_BSC6/07B/00" 418 090529 1059
RXOCF-150 GDP002 2
DOOR OPEN
A2/EXT "BAP_BSC6/07B/00" 874 090529 1346
RXOCF-401 BBN001 2
SITE ON BATTERY

# 3  
Old 06-02-2009
Hammer & Screwdriver Here is one way

Code:
> cat file22
A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 
RXOCF-465 PDTR11 1

SITE ON BATTERY 

A2/EXT "BAP_BSC6/07B/00" 418 090529 1059 
RXOCF-150 GDP002 2

DOOR OPEN 
A2/EXT "BAP_BSC6/07B/00" 874 090529 1346 
RXOCF-401 BBN001 2

SITE ON BATTERY

> grep "[A-Z0-9]" file22
A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 
RXOCF-465 PDTR11 1
SITE ON BATTERY 
A2/EXT "BAP_BSC6/07B/00" 418 090529 1059 
RXOCF-150 GDP002 2
DOOR OPEN 
A2/EXT "BAP_BSC6/07B/00" 874 090529 1346 
RXOCF-401 BBN001 2
SITE ON BATTERY

And that command can redirect output to a new file, such as
Code:
grep "[A-Z0-9]" file22 > file22a

# 4  
Old 06-02-2009
Another one:

Code:
awk 'NF' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removing multiple lines from input file, if multiple lines match a pattern.

GM, I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed. I am assuming that sed, awk or even perl could do what I need. I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 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. UNIX for Dummies Questions & Answers

Removing empty lines at the end of a Tab-delimited file

I'm trying to remove all of the empty lines at the end of a Tab delimited file. They have no data just tabs. I've tried may things, here are a couple: sed /^\t.\t/d File1 > File2 sed /^\t{44}/d File1 > File2 What am I missing? (9 Replies)
Discussion started by: SirHenry1
9 Replies

4. Shell Programming and Scripting

Extract lines between 2 strings add white space

I'm trying to extract all the lines between 2 strings (including the lines containing the strings) To make the strings unique I need to include white space if possible. I'm not certain how to do that. sed -n '/ string1 /,/string2/p' infile > outfile & (4 Replies)
Discussion started by: dcfargo
4 Replies

5. Shell Programming and Scripting

Break lines up into single lines after each space in every line

It sounds a bit confusing but what I have is a text file like the example below (without the Line1, Line2, Line3 etc. of course) and I want to move every group of characters into a new line after each space. Example of text file; line1 .digg-widget-theme2 ul { background: rgb(0, 0, 0) none... (7 Replies)
Discussion started by: lewk
7 Replies

6. Shell Programming and Scripting

Removing blank lines from comma seperated and space seperated file.

Hi, I want to remove empty/blank lines from comma seperated and space seperated files Thanks all for help (11 Replies)
Discussion started by: pinnacle
11 Replies

7. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

8. Shell Programming and Scripting

using AWK see the upper lines and lower lines of the strings??

Hi experts, You cool guys already given me the awk script below- awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log Morever, i have one more things- when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string. Line 1.... (3 Replies)
Discussion started by: thepurple
3 Replies

9. Shell Programming and Scripting

Find lines with space between strings

Hello all, I am having trouble with setting up a regular expression used with egrep. My script reads an input file a line at a time. I would like the egrep command to search for the following pattern: server name at the beginning of the line, then one or more spaces, and then a pound sign. ... (5 Replies)
Discussion started by: Galt
5 Replies

10. Shell Programming and Scripting

re: removing trailing space from lines

Not sure why this thread was closed without any explanation, but you can do what you're asking with sed 's/]*$//g' < sourceFile > destFile (1 Reply)
Discussion started by: oombera
1 Replies
Login or Register to Ask a Question