Loading ...
Sorry, an error occurred while loading the content.

Re: Deleting characters at the beginning of a line

Expand Messages
  • Cameron Simpson
    ... sed s/.....// file2 removes 5 characters. ... Gah! No. ... [...] ... sed s:.*home/:: file2 Note the different pattern delimiters;
    Message 1 of 5 , Jun 11, 2007
    • 0 Attachment
      On 11Jun2007 11:24, Michael Sullivan <michael@...> wrote:
      | On Mon, 2007-06-11 at 09:45 -0500, Robert C Wittig wrote:
      | > Michael Sullivan wrote:
      | > > Is there an easy way to delete a set number characters from the
      | > > beginning of a line,

      sed 's/.....//' <file1 >file2

      removes 5 characters.

      | or do I just need to write a perl script to do it?

      Gah! No.

      | My actual application for this is thus: I have a file of information in
      | this format. It is diff output:
      |
      | < -r--r--r-- michael/users 1204048 2007-05-25 13:34
      | home/michael/.evolution/cache/tmp/evolution-tmp-g9stix/voice-message.wav
      [...]
      | What I need to do is extract everything after the string 'home'. Only
      | that. I tried using `cat diff.txt | cut -c 51-`, but it seems that the
      | filename in the listing does not always start in column 51. Is there a
      | way I can extract only the filename from the listing? I tried man tr,
      | but I didn't understand it...

      sed 's:.*home/::' <file1 >file2

      Note the different pattern delimiters; because I'm aiming for "home/",
      using / as the delimiter would be inconvenient.
      --
      Cameron Simpson <cs@...> DoD#743
      http://www.cskk.ezoshosting.com/cs/

      The most incomprehensible thing about the world is that it is at all comprehensible.
      - Albert Einstein
    • Jim Reimer
      ... man cut Probably the simplest approach. -- -jdr-
      Message 2 of 5 , Jun 11, 2007
      • 0 Attachment
        Michael Sullivan wrote:

        > Is there an easy way to delete a set number characters from the
        > beginning of a line, or do I just need to write a perl script to do it?


        man cut

        Probably the simplest approach.

        --
        -jdr-
      Your message has been successfully submitted and would be delivered to recipients shortly.