HP3000-L Archives

April 2016, Week 5

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
krikor Gullekian <[log in to unmask]>
Reply To:
krikor Gullekian <[log in to unmask]>
Date:
Fri, 29 Apr 2016 20:13:28 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (105 lines)
Hi Barry,
Thanks for the info, but that is the first thing I tried and it didn't work, that is why I was wondering.
Thanks,Krikor

      From: Barry Lake <[log in to unmask]>
 To: krikor Gullekian <[log in to unmask]> 
Cc: krikor Gullekian <[log in to unmask]>; [log in to unmask]
 Sent: Friday, April 29, 2016 12:54 PM
 Subject: Re: Unix, delete a line only if the first 30 characters are blank
   

On 4/29/16 8:23 AM, krikor Gullekian wrote:
> How can I delete in an easy way a line if the first 30 characters are
> blank in unix. I use sed, "sed '/^$/d'" but this will delete only if
>the entire line is blank.


Regular expressions are your friend. Observe:


fuji:~ root# cat demo.txt
zero
  one
  two
    three
    four
      five
      six
        seven
        eight
          nine
          ten
fuji:~ root#


So we have a file in which each line starts with one more space than the 
line before. If we want to delete all lines beginning with at least one 
space...


fuji:~ root# sed '/^ /d' demo.txt
zero
fuji:~ root#


Now delete all lines beginning with at least three spaces...


fuji:~ root# sed '/^  /d' demo.txt
zero
  one
  two
fuji:~ root#


Finally all lines beginning with seven spaces...


fuji:~ root# sed '/^      /d' demo.txt
zero
  one
  two
    three
    four
      five
      six
fuji:~ root#


So, obviously, you could accomplish your task in brute force fashion by 
typing out 30 spaces in the sed pattern, rather than 1, 3 or 7 as I have 
shown. But better would be to use a regular expression similar to this:


fuji:~ root# sed '/^ \{9\}/d' demo.txt
zero
  one
  two
    three
    four
      five
      six
        seven
        eight
fuji:~ root#


Here we're saying: "delete all lines beginning with some pattern, which 
happens to be a space, in which that pattern is repeated 9 times". Note 
that the curly braces {} have to be escaped in order to give them that 
special meaning, otherwise you'd be matching the literal curly brace 
characters. So in your case, of course, you'd use 30 instead of 9.


Regards,

Barry Lake
Allegro Consultants, Inc.



* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
  

ATOM RSS1 RSS2