Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Shell Scripting

  1. #1
    Join Date
    Sep 2011
    Beans
    14

    Exclamation Shell Scripting

    how to replace Alt+Enter from within text file .

    sample input book2.txt is below..

    1212||sdfsdfsdf fgkdjfkgljlsdfg||sdfsdf
    4454||"sadfsdfg
    sdfgsdfg
    sdf"||sdfgdfg
    4454||ds gkdkjfhgskjfsdhkjg||sdfsdf

    in above data, each line start with number. and is "||" delimited, but the 3rd record is broken into 3 lines due to alt+enter.

    sed cntrl+J not helped

    Regards
    Rohit
    Last edited by rohit verma; October 8th, 2012 at 04:14 PM.

  2. #2

    Re: Shell Scripting

    replace it with what?
    Windows assumes the user is an idiot.
    Linux demands proof.

  3. #3
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,698

    Re: Shell Scripting

    Sorry, I don't understand. What are you trying to replace, and what are you trying to put there instead?

  4. #4
    Join Date
    Sep 2011
    Beans
    14

    Re: Shell Scripting

    Thanks buddies for response..

    i need to replace Alt+enter with any character...
    Blank space / abc any thing


    regards
    Rohit

  5. #5
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,698

    Re: Shell Scripting

    I don't know what you mean by Alt-Enter. Can you provide before and after examples? Printouts of commands like:
    hd before-file
    hd after-file
    would be great.

    Are you trying to merge all the lines together as one long line?

  6. #6
    Join Date
    Sep 2011
    Beans
    14

    Re: Shell Scripting

    hi the cog,

    sample input u can build by following below steps.
    1>open ms excel (on windows ).
    2>fill 2 to 3 cells in 2 or more row.
    3>while editing any cell , hit Alt + Enter and u will see new line in same cell, write few more text in new line.
    4>save file as tab delimited .txt file .
    5> open the same in any text editor..
    6> you will find line on which you used (alt + enter) is broken..


    hope i am not confusing you all.. Sorry if so.

  7. #7
    Join Date
    Sep 2011
    Beans
    14

    Re: Shell Scripting

    Input ::
    1212||sdfsdfsdf fgkdjfkgljlsdfg||sdfsdf
    4454||"sadfsdfg
    sdfgsdfg
    sdf"||sdfgdfg
    4454||ds gkdkjfhgskjfsdhkjg||sdfsdf


    Output:::
    1212||sdfsdfsdf fgkdjfkgljlsdfg||sdfsdf
    4454||"sadfsdfg sdfgsdfg sdf"||sdfgdfg
    4454||ds gkdkjfhgskjfsdhkjg||sdfsdf

  8. #8
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Shell Scripting

    If you just want to strip all occurrences of a particular character you could just use 'tr'

    However if the character occurs elsewhere and you only want to replace it in this particular context, you could try modifying this standard sed one-liner:

    # if a line begins with an equal sign, append it to the previous line # and replace the "=" with a single space
    sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
    so that it joins lines when the following line does NOT begin with a digit, e.g.

    Code:
    sed -e :a -e '$!N;s/\n\([^0-9]\)/\1/;ta' -e 'P;D'
    If the separating character really is something other than newline (\n) you should be able to specify it via its ASCII hex value e.g. for \n you could also write (substitute your \x value as appropriate)

    Code:
    sed -e :a -e '$!N;s/\xA\([^0-9]\)/\1/;ta' -e 'P;D'
    Last edited by steeldriver; October 8th, 2012 at 06:18 PM.

  9. #9
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,698

    Re: Shell Scripting

    Hmm. Not as easy as it looks, I think.
    I like the look of the first answer here:
    http://stackoverflow.com/questions/8...text-in-a-file

  10. #10
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,698

    Re: Shell Scripting

    Hmm. Not as easy as it looks, I think.
    I like the look of the first answer here:
    http://stackoverflow.com/questions/8...text-in-a-file

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •