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
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
sed 's/ */ /g' file_name
This will replace 2 or more spaces to single space.
Hi Magesh!
Try 'cat -s' probably it'll solve your problem
Hope this helps you,
Input file:
1
2
3
4
5
6
7
8
9
10
$sed '/^$/{
N
/^\n$/s/^\n$//
}' a
1
2
3
4
5
6
7
8
9
10
sidorenko ur soln was simple and effective thanks...
as well as urs skmdu..
Thanks Guys
Or using awk
awk '!NF{getline;$0=(!NF)?$0:RS$0}1' file
Or using Perl:
perl -lne 'if (/^$/ and $n==0){$n++; print} elsif(!/^$/){$n=0; print} else{$n++}' filename
tyler_durden
GUYs one problem..
My Box is SunOS .. Whereas all the command runs fine in AIX but it throws error in SunOS (except the perl one)..
But i will really like to use the awk command or anything instead of Perl..
Could anyone gives me the command which will work in SunOS..
Try POSIX awk (/usr/xpg4/bin/awk) on SunOS.
Another awk one:
t$ cat file
record one
record two
record three
$ awk -v RS="\n\n" -v ORS="\n" 1 file
record one
record two
record three
But honestly, as already mentioned above, cat -s is easier.