Replace two blank line with a single blank line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace two blank line with a single blank line
# 1  
Old 09-14-2009
Replace two blank line with a single blank line

Hi Guys,

I have a file in which each set of records are separated by two blank line. I want to replace it with a single blank line.

Can you guys help me out?

Regards,
Magesh
# 2  
Old 09-14-2009
sed 's/ */ /g' file_name

This will replace 2 or more spaces to single space.
# 3  
Old 09-14-2009
Quote:
Originally Posted by mac4rfree
I have a file in which each set of records are separated by two blank line. I want to replace it with a single blank line.
Hi Magesh!
Try 'cat -s' probably it'll solve your problem
# 4  
Old 09-14-2009
Hope this helps you,

Input file:
1


2

3
4

5
6


7
8


9
10

Code:
$sed '/^$/{
N
/^\n$/s/^\n$//
}' a
1

2

3
4

5
6

7
8

9
10

# 5  
Old 09-14-2009
sidorenko ur soln was simple and effective thanks...

as well as urs skmdu..

Thanks Guys
# 6  
Old 09-14-2009
Or using awk
Code:
awk '!NF{getline;$0=(!NF)?$0:RS$0}1' file

# 7  
Old 09-14-2009
Or using Perl:

Code:
perl -lne 'if (/^$/ and $n==0){$n++; print} elsif(!/^$/){$n=0; print} else{$n++}' filename

tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 Replies

2. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

3. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

4. Shell Programming and Scripting

Need help to replace a pattern with a blank line

Need help to replace the line beginning with tcp_sendspace with a blank line. # cat if en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN> inet 10.27.53.21 netmask 0xffffff00 broadcast 10.207.52.255 inet... (11 Replies)
Discussion started by: sags007_99
11 Replies

5. Shell Programming and Scripting

replace blank line number

hlow all i need help how can i replace blank number with awk input.txt 300::|355264313178490 301::|358814003239510 302::|358316038113400 303::|357954002633660 304::|354072040694090 305::|356956015214190 306::|352943020525180 307::|359574033836610 308::|381810990023580 so will be like... (4 Replies)
Discussion started by: zvtral
4 Replies

6. Shell Programming and Scripting

Fill the empty line by adding line before blank line

FIle A "A" 2 aa 34 3 ac 5 cd "B" 3 hu 67 4 fg 5 gy output shud be A"" 2 aa 34 "A" 3 ac 34 "A" 5 cd 34 "B" 3 hu 67 "B" 4 fg 67 "B" 5 gy 67 (6 Replies)
Discussion started by: cdfd123
6 Replies

7. Shell Programming and Scripting

deleting blank line and row containing certain words in single sed command

Hi Is it possible to do the following in a single command /usr/xpg4/bin/sed -e '/rows selected/d' /aemu/CALLAUTO/callauto.txt > /aemu/CALLAUTO/callautonew.txt /usr/xpg4/bin/sed -e '/^$/d' /aemu/CALLAUTO/callautonew.txt > /aemu/CALLAUTO/callauto_new.txt exit (1 Reply)
Discussion started by: aemunathan
1 Replies

8. Shell Programming and Scripting

how to replace a line in file with blank line

Hi I nned cmd to which will help me to replace a line in file with blank line e.g. file1 a b c d e after running cmd I shud get file1 b c d e (5 Replies)
Discussion started by: tarunn.dubeyy
5 Replies

9. Shell Programming and Scripting

sed: delete regex line and next line if blank

Hi, I want to write a sed script which from batiato: batiato/giubbe: pip_b.2.txt pip_b.3.txt pip_b.3mmm.txt bennato: bennato/peterpan: 123.txt consoli: pip_a.12.txt daniele: (2 Replies)
Discussion started by: one71
2 Replies

10. Shell Programming and Scripting

Replace blank spaces by single tab, and right alignment

Folks, I am wondering if anyone solve this problem. What I want to know is, 1. Delete all white spaces including leading blank space in each line (e.g. line 2), and replace such spaces by single tab except leading blank space 2. Then, align all columns to the right. But, output white space... (1 Reply)
Discussion started by: Jae
1 Replies
Login or Register to Ask a Question