<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: sed help in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139982#M31533</link>
    <description>Bonsoir,&lt;BR /&gt;&lt;BR /&gt;Just found this at &lt;A href="http://pwet.fr/man/linux/commandes/sed" target="_blank"&gt;http://pwet.fr/man/linux/commandes/sed&lt;/A&gt; :&lt;BR /&gt;&lt;BR /&gt;-r, --regexp-extended &lt;BR /&gt;use extended regular expressions in the script&lt;BR /&gt;&lt;BR /&gt;It sounds like like -E option for grep with HP-UX, no ?&lt;BR /&gt;&lt;BR /&gt;Could you try to add -r option and tell us ?&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Eric&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 05 Feb 2008 16:59:38 GMT</pubDate>
    <dc:creator>Eric SAUBIGNAC</dc:creator>
    <dc:date>2008-02-05T16:59:38Z</dc:date>
    <item>
      <title>sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139975#M31526</link>
      <description>&lt;!--!*#--&gt;I can use some help using sed. I have a file that has a lot of trailing spaces. &lt;BR /&gt;I use vi to edit the file, and search and replace all the trailing space like so&lt;BR /&gt;:%s/[ ]*$//&lt;BR /&gt;&lt;BR /&gt;Although, when I try to use sed, I am not able to edit the file at all. Here is how I am trying to do this&lt;BR /&gt;&lt;BR /&gt;cat filename | sed -e 's/[ ]*$//' &lt;BR /&gt;&lt;BR /&gt;This does not edit the file at all. What could I be doing wrong? Any help is greatly appreciated. &lt;BR /&gt;-S</description>
      <pubDate>Mon, 04 Feb 2008 16:30:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139975#M31526</guid>
      <dc:creator>slydmin</dc:creator>
      <dc:date>2008-02-04T16:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139976#M31527</link>
      <description>I think I may have a solution  using tr &lt;BR /&gt;&lt;BR /&gt; cat fielname | tr -d '\032* $'&lt;BR /&gt;&lt;BR /&gt;Although, I need to confirm it with the QA ppl to make sure the file works for them. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Feb 2008 16:48:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139976#M31527</guid>
      <dc:creator>slydmin</dc:creator>
      <dc:date>2008-02-04T16:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139977#M31528</link>
      <description>You need to append g (to allow sed to fix all the matched cases and not just the first one). So it's:&lt;BR /&gt; sed -e 's/[ ]*$//g' filename&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Feb 2008 18:24:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139977#M31528</guid>
      <dc:creator>Alexander Chuzhoy</dc:creator>
      <dc:date>2008-02-04T18:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139978#M31529</link>
      <description>Bonsoir -S,&lt;BR /&gt;&lt;BR /&gt;It should work asis, that is without 'g' flag. Under HP-UX it works well.&lt;BR /&gt;&lt;BR /&gt;As far as I know, regular expressions are satisfied with the largest number of characters that can match the expression. If it was not the case, and IMHO, '*' in a regular expression would have no sens. And '[ ]*$' clearly means : 0 or more spaces before end of line ! So it shoul work.&lt;BR /&gt;&lt;BR /&gt;Don't know Linux as well as HP-UX but maybe there is a limitation on implementation of sed. Maybe there is a special option to tell 'sed' to use extended regular expressions ? I have this beahavior under HP-UX with 'grep' : if you don't use -E option, 'grep' doesn't treat correctly all regular expressions.&lt;BR /&gt;&lt;BR /&gt;An other idea : '[]' is used to match a list of characters. As you have only one character, space, may be '[ ]' is not correctly interpreted ? So try this :&lt;BR /&gt;&lt;BR /&gt;cat filename | sed -e 's/ *$//'&lt;BR /&gt;&lt;BR /&gt;Hope this will help&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Eric&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Feb 2008 18:46:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139978#M31529</guid>
      <dc:creator>Eric SAUBIGNAC</dc:creator>
      <dc:date>2008-02-04T18:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139979#M31530</link>
      <description>As far as I'm aware, none of these commands 'edit' the file in place, but alter an output stream in the pipe.&lt;BR /&gt;&lt;BR /&gt;If you want to edit a file in place, you can use:&lt;BR /&gt;&lt;BR /&gt;perl -pi -e 's/\s+$//' filename</description>
      <pubDate>Mon, 04 Feb 2008 20:16:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139979#M31530</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2008-02-04T20:16:32Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139980#M31531</link>
      <description>Good point Stuart.&lt;BR /&gt;&lt;BR /&gt;slydmin, in order to actually update the content of the file you can redirect the output:&lt;BR /&gt;sed -e 's/[ ]*$//g' &amp;gt; newfile; mv newfile origfile;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;make sure you have a backup of the original file.</description>
      <pubDate>Tue, 05 Feb 2008 06:43:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139980#M31531</guid>
      <dc:creator>Alexander Chuzhoy</dc:creator>
      <dc:date>2008-02-05T06:43:29Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139981#M31532</link>
      <description>Alexander,&lt;BR /&gt;  I was actually doing that, but did not mention in my original email. &lt;BR /&gt;&lt;BR /&gt;sed -e 's/[ ]*$//'&lt;INPUTFILE&gt;outputfile&lt;BR /&gt;&lt;BR /&gt;I tried everyone's suggestion but none gave desired output. &lt;BR /&gt;&lt;BR /&gt;I have a csv file, with say about 14 comma separated fields. The last field has a lot of spaces in it. &lt;BR /&gt;vim works like a charm (:%s![ ]*$!), although we are going to have a large number of files to  process and manually doing it does not make sense. &lt;BR /&gt;&lt;BR /&gt;So this attempt to use same regex with sed does not work. tr -d \032 works, although it removes white space from everywhere in the file.&lt;BR /&gt;I will copy 3 lines from the file and attache it herewith, although the data is changed. &lt;BR /&gt;&lt;BR /&gt;I am stumped at this point. &lt;BR /&gt;&lt;/INPUTFILE&gt;</description>
      <pubDate>Tue, 05 Feb 2008 16:31:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139981#M31532</guid>
      <dc:creator>slydmin</dc:creator>
      <dc:date>2008-02-05T16:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139982#M31533</link>
      <description>Bonsoir,&lt;BR /&gt;&lt;BR /&gt;Just found this at &lt;A href="http://pwet.fr/man/linux/commandes/sed" target="_blank"&gt;http://pwet.fr/man/linux/commandes/sed&lt;/A&gt; :&lt;BR /&gt;&lt;BR /&gt;-r, --regexp-extended &lt;BR /&gt;use extended regular expressions in the script&lt;BR /&gt;&lt;BR /&gt;It sounds like like -E option for grep with HP-UX, no ?&lt;BR /&gt;&lt;BR /&gt;Could you try to add -r option and tell us ?&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Eric&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Feb 2008 16:59:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139982#M31533</guid>
      <dc:creator>Eric SAUBIGNAC</dc:creator>
      <dc:date>2008-02-05T16:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139983#M31534</link>
      <description>Eric,&lt;BR /&gt;  I thought I had tried that (sed -r). But I gave it a try and it did not work. &lt;BR /&gt;&lt;BR /&gt;What is interesting though, the file I uploaded , if that were to be manipulated with sed -r 's/[ ]*$//g' , I get the desired output but not on the original file. &lt;BR /&gt;&lt;BR /&gt;The original file has a line count of about 25000. I tried splitting it up in to 5000 line files, but still am not having success. &lt;BR /&gt;&lt;BR /&gt;I am going to try and use perl to see if I can use the expression posted to my OP (it removed all spaces, just like tr -d\032).&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;-S</description>
      <pubDate>Tue, 05 Feb 2008 17:16:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139983#M31534</guid>
      <dc:creator>slydmin</dc:creator>
      <dc:date>2008-02-05T17:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139984#M31535</link>
      <description>Actually I was wrong about the perl expression, it does not remove all white spaces like tr does.&lt;BR /&gt;&lt;BR /&gt;It removes the white space(s) at the end of the line, but not all new lines are lost.&lt;BR /&gt;&lt;BR /&gt;2nd line is not a continuation of the 1st. &lt;BR /&gt;&lt;BR /&gt;Will try a few more things, but I stand corrected on the tr /perl comparison.&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Feb 2008 17:37:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139984#M31535</guid>
      <dc:creator>slydmin</dc:creator>
      <dc:date>2008-02-05T17:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139985#M31536</link>
      <description>I may have the solution after all.&lt;BR /&gt;&lt;BR /&gt;Stuart's command line perl expression works very well with one minor change&lt;BR /&gt;&lt;BR /&gt;perl -pi -e 's/\s+$/\n/g' filename&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The addition of \n -newline ensures that lines are kept separate. &lt;BR /&gt;&lt;BR /&gt;Thanks all for the help&lt;BR /&gt;</description>
      <pubDate>Tue, 05 Feb 2008 17:55:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139985#M31536</guid>
      <dc:creator>slydmin</dc:creator>
      <dc:date>2008-02-05T17:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: sed help</title>
      <link>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139986#M31537</link>
      <description>Bonsoir,&lt;BR /&gt;&lt;BR /&gt;It must work with sed ... grrrr ! And I the solution ... IMHO ;-)&lt;BR /&gt;&lt;BR /&gt;You said "What is interesting though, the file I uploaded , if that were to be manipulated with sed -r 's/[ ]*$//g' , I get the desired output but not on the original file"&lt;BR /&gt;&lt;BR /&gt;Here is the difference : NOT ON THE ORIGINAL FILE.&lt;BR /&gt;&lt;BR /&gt;Why does it work with perl and not with sed ?You use [ ] with sed wich means space. But you use \s with perl wich means blankspace : blankspace is characters producing white-space in displayed text : spaces and tabulations. &lt;BR /&gt;&lt;BR /&gt;Here again is the difference : THE ORIGINAL FILE INCLUDES SPACES AND TABULATIONS.&lt;BR /&gt;&lt;BR /&gt;So the answer is very simple : all lines are not necessary spaces terminated in your original file. Make a ontrol with 'od -c' ...&lt;BR /&gt;&lt;BR /&gt;For detailed examples see the attached file. &lt;BR /&gt;&lt;BR /&gt;Here is the definitive answer to work with sed. 2 solutions :&lt;BR /&gt;&lt;BR /&gt;sed -r 's/[[:space:]]*$//' filename&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;SPACE=`echo " \t\c"`&lt;BR /&gt;sed -r 's/['"$SPACE"']*$//' filename&lt;BR /&gt;&lt;BR /&gt;What about it ? :-)&lt;BR /&gt;&lt;BR /&gt;Have a nice WE&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;&lt;BR /&gt;Eric&lt;BR /&gt;</description>
      <pubDate>Fri, 08 Feb 2008 19:04:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/sed-help/m-p/4139986#M31537</guid>
      <dc:creator>Eric SAUBIGNAC</dc:creator>
      <dc:date>2008-02-08T19:04:43Z</dc:date>
    </item>
  </channel>
</rss>

