Using sed to delete blank spaces

Using sed to delete blank spaces

Post by btna » Sat, 08 Jan 2005 10:08:11



Hi all,

I have a file that looks like this:

<SP><SP><SP>ABCDE
<SP><SP><SP>FGHI
<SP><SP><SP>
<SP><SP><SP>MNBH

<SP> is a space. I need to be able to delete the spaces from the line
that does not have any characters (Line # 3). The other lines need to
have the 2 spaces at the beginning.
Any ideas on how to do this?

Thanks in advance,

BTNA

 
 
 

Using sed to delete blank spaces

Post by Chris F.A. Johnso » Sat, 08 Jan 2005 10:20:39



> Hi all,

> I have a file that looks like this:

><SP><SP><SP>ABCDE
><SP><SP><SP>FGHI
><SP><SP><SP>
><SP><SP><SP>MNBH

><SP> is a space. I need to be able to delete the spaces from the line
> that does not have any characters (Line # 3). The other lines need to
> have the 2 spaces at the beginning.
> Any ideas on how to do this?

    If you want to keep the (blank) lines:

awk '/[^ ]/ { print; next } { print "" }'

    If not:

awk '/[^ ]/ { print; next }'

--
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

Using sed to delete blank spaces

Post by Ed Morto » Sat, 08 Jan 2005 10:30:30



> Hi all,

> I have a file that looks like this:

> <SP><SP><SP>ABCDE
> <SP><SP><SP>FGHI
> <SP><SP><SP>
> <SP><SP><SP>MNBH

> <SP> is a space. I need to be able to delete the spaces from the line
> that does not have any characters (Line # 3). The other lines need to
> have the 2 spaces at the beginning.

2 spaces or 3?

Quote:> Any ideas on how to do this?

Assuming you want to remove all leading spaces from every empty line but
keep all leading spaces on the other lines, in gawk it's just:

        awk '!NF{$1=$1}1' file

Regards,

        Ed.

Quote:> Thanks in advance,

> BTNA

 
 
 

Using sed to delete blank spaces

Post by Alan Conno » Sat, 08 Jan 2005 10:38:26



Quote:> Hi all,

> I have a file that looks like this:

><SP><SP><SP>ABCDE FGHI
><SP><SP><SP>
><SP><SP><SP>MNBH

><SP> is a space. I need to be able to delete the spaces from the
>line that does not have any characters (Line # 3). The other
>lines need to have the 2 spaces at the beginning.  Any ideas on
>how to do this?

> Thanks in advance,

Try this, btana:

sed -e '/^   $/d' -e '/^   [^ ]*/{;s/^   /  /;}' inputfile >\
outputfile

There's a tutorial on basic regexes (regular expressions;REs) on
my ed website:

http://tinyurl.com/2aa6g

AC

 
 
 

Using sed to delete blank spaces

Post by Rakesh Sharm » Sat, 08 Jan 2005 11:01:29



> Hi all,

> I have a file that looks like this:

> <SP><SP><SP>ABCDE
> <SP><SP><SP>FGHI
> <SP><SP><SP>
> <SP><SP><SP>MNBH

> <SP> is a space. I need to be able to delete the spaces from the line
> that does not have any characters (Line # 3). The other lines need to
> have the 2 spaces at the beginning.
> Any ideas on how to do this?

      sed -e '/[^ ]/b' -e 'x' yourfile
 
 
 

Using sed to delete blank spaces

Post by Rakesh Sharm » Sat, 08 Jan 2005 11:10:38


Quote:> sed -e '/[^ ]/b' -e 'x' yourfile

should be

      sed -e '/[^ ]/b' -e 'x;p;x;d' yourfile

 
 
 

Using sed to delete blank spaces

Post by Stephane CHAZELA » Sat, 08 Jan 2005 15:56:14


2005-01-6, 17:08(-08), btna:
Quote:> I have a file that looks like this:

> <SP><SP><SP>ABCDE
> <SP><SP><SP>FGHI
> <SP><SP><SP>
> <SP><SP><SP>MNBH

> <SP> is a space. I need to be able to delete the spaces from the line
> that does not have any characters (Line # 3). The other lines need to
> have the 2 spaces at the beginning.
> Any ideas on how to do this?

[...]

If you need to delete the spaces but not the lines:

sed 's/^ *$//'

--
Stephane

 
 
 

Using sed to delete blank spaces

Post by John W. Krah » Sun, 09 Jan 2005 00:37:08



> I have a file that looks like this:

> <SP><SP><SP>ABCDE
> <SP><SP><SP>FGHI
> <SP><SP><SP>
> <SP><SP><SP>MNBH

> <SP> is a space. I need to be able to delete the spaces from the line
> that does not have any characters (Line # 3). The other lines need to
> have the 2 spaces at the beginning.
> Any ideas on how to do this?

perl -lpe'/\S/?s/^\s+/  /:s/\s+//' yourfile

John
--
use Perl;
program
fulfillment

 
 
 

1. delete blank lines with sed.

This has likely been asked to death. And I have it in my notes somewhere
but I cant find them. I dont know what the regular exprsion is for
:space: is that I can use with sed.

sed -e '/^#/d' filename > out     deletes lines that begin with # 's.
How do I remove blank lines ?

TIA

--
==========================================
Rocke Robertson
PWGSC-GTIS-CPS
Voice (613) 748-4604
Fax   (613) 748-4843

==========================================

2. Something zapped group wheel

3. deleting blank lines with sed

4. Korn shell script & VT102

5. sed/awk question : delete first blank in every line

6. Use of SIGUSR1 within the JVM/Solaris 8

7. sed command to replace text with blank spaces

8. Problems downloading RH 7.3

9. find and delete blank space

10. Delete the hold space in sed?

11. sed: how to delete string of spaces before a CR character?

12. using sed to remove blank lines ??

13. inserting a blank line after every line - using sed