<?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: problems with &amp;quot;/&amp;quot; in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992868#M100528</link>
    <description>You're not getting the expected output because (already stated in Dennis' post) of single quotes which prevent variable expansion. Moreover using "/" within the substitution command will prevent parsing of the line owing to ambiguity if $Dir contains slashes "/".&lt;BR /&gt;&lt;BR /&gt;For example...&lt;BR /&gt;&lt;BR /&gt;Dir=/home/mydir&lt;BR /&gt;&lt;BR /&gt;and the input file contains:&lt;BR /&gt;Product Name,XXX/YY&lt;BR /&gt;&lt;BR /&gt;sed -n '/^Product Name/s/.*/&amp;amp;-$Dir/p' $FILE&lt;BR /&gt;Product Name,XXX/YY-$Dir&lt;BR /&gt;&lt;BR /&gt;notice that variable $Dir has not been expanded to its contents "/home/mydir". Now replace single quotes with double quotes and try the command again:&lt;BR /&gt;&lt;BR /&gt;sed -n "/^Product Name/s/.*/&amp;amp;-$Dir/p" $FILE&lt;BR /&gt;sed: Function /^Product Name/s/.*/&amp;amp;-/home/mydir/p cannot be parsed.&lt;BR /&gt;&lt;BR /&gt;the command errors out owing to the presence of "/" characters in $Dir variable, so change the substitution command delimiters to an unambiguous character such as "|" or ";" etc.&lt;BR /&gt;&lt;BR /&gt;sed -n "/^Product Name/s|.*|&amp;amp;-$Dir|p" $FILE&lt;BR /&gt;Product Name,XXX/YY-/home/mydir&lt;BR /&gt;&lt;BR /&gt;which gives the expected output.&lt;BR /&gt;&lt;BR /&gt;~hope it helps</description>
    <pubDate>Wed, 26 Jul 2006 05:02:10 GMT</pubDate>
    <dc:creator>Sandman!</dc:creator>
    <dc:date>2006-07-26T05:02:10Z</dc:date>
    <item>
      <title>problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992862#M100522</link>
      <description>Dear Gurus,&lt;BR /&gt;&lt;BR /&gt;Am trying to replace certain line in my file &lt;BR /&gt;&lt;BR /&gt;For Example:&lt;BR /&gt;&lt;BR /&gt;Product Name,XXX/YY&lt;BR /&gt;&lt;BR /&gt;What i want to do is replace XXX/YY with the following:&lt;BR /&gt;&lt;BR /&gt;Product Name,XXX/YY-Dir&lt;BR /&gt;&lt;BR /&gt;and i have the following line in my script:&lt;BR /&gt;&lt;BR /&gt;export ddev=$(awk -F "," '/^Product Name/ {print $2}' $FILE|awk -F " " '{print $1}')&lt;BR /&gt;perl -pi -e "s/^Product Name,$ddev/Product Name,$ddev"-"$Dir/" $FILE&lt;BR /&gt;&lt;BR /&gt;the ddev variable sometime contains "/"  that it does not contain the correct match because of the "/" and causes an error.&lt;BR /&gt;&lt;BR /&gt;I know something is wrong in the perl command.&lt;BR /&gt;&lt;BR /&gt;Please help!&lt;BR /&gt;</description>
      <pubDate>Mon, 24 Jul 2006 21:18:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992862#M100522</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2006-07-24T21:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992863#M100523</link>
      <description>&amp;gt;the ddev variable sometime contains "/" that it does not contain the correct match because of the "/" and causes an error.&lt;BR /&gt;&lt;BR /&gt;It seems ddev is set by awk and that will have the "/".  It seems you must tell perl that you must use a different delimiter other than the "/"?&lt;BR /&gt;&lt;BR /&gt;(Any reason you are using both awk and perl instead of just one tool?)&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 24 Jul 2006 21:44:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992863#M100523</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-07-24T21:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992864#M100524</link>
      <description>For you immediate question, just use something other then "/" as  the delimitors in the substitute command. For example use ";".&lt;BR /&gt;&lt;BR /&gt;perl -pi -e "s;^Product Name,$ddev;Product Name,$ddev"-"$Dir;" $FILE&lt;BR /&gt;&lt;BR /&gt;But why jump through that double AWK hoop?&lt;BR /&gt;Perl can do it all!&lt;BR /&gt;&lt;BR /&gt;It looks like you simply want&lt;BR /&gt;&lt;BR /&gt;(untested)&lt;BR /&gt;&lt;BR /&gt;perl -pi -e  's/(^ProductName.*)$/$1-Dir/' $FILE&lt;BR /&gt;&lt;BR /&gt;That is... if a line starts with product name then remember everything up to the EOL in $1 and replace it by $1-dir.&lt;BR /&gt;&lt;BR /&gt;You could also have done that in AWK:&lt;BR /&gt;&lt;BR /&gt;awk '/^ProductName/{$0 = $0 "-Dir"} {print}' $FILE&lt;BR /&gt;&lt;BR /&gt;Oh wait... $Dir is a variable also.&lt;BR /&gt;Where does it come from? Pick up also?&lt;BR /&gt;Or pass it as a parameter or variable.&lt;BR /&gt;&lt;BR /&gt;awk -v dir=$Dir '/^ProductName/{$0 = $0 "-" dir} {print}' $FILE&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 24 Jul 2006 21:51:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992864#M100524</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-07-24T21:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992865#M100525</link>
      <description>Choose a different delimiter within the substitution command.&lt;BR /&gt;&lt;BR /&gt;Instead of:&lt;BR /&gt;"s/pattern_to_match/replacement_pattern/p"&lt;BR /&gt;use:&lt;BR /&gt;"s%pattern_to_match%replacement_pattern%p"&lt;BR /&gt;&lt;BR /&gt;Replace the "/" with "%" or with any character that is unambiguous, one that is not found in the pattern you're trying to match. The two lines in your script can be replaced by a single one for compacting code and improving its legibility.&lt;BR /&gt;&lt;BR /&gt;replace...&lt;BR /&gt;export ddev=$(awk -F "," '/^Product Name/ {print $2}' $FILE|awk -F " " '{print $1}')&lt;BR /&gt;perl -pi -e "s/^Product Name,$ddev/Product Name,$ddev"-"$Dir/" $FILE&lt;BR /&gt;&lt;BR /&gt;...with&lt;BR /&gt;# sed -n "/^Product Name/s%\(.*\)%&amp;amp;-$Dir%p" $FILE&lt;BR /&gt;&lt;BR /&gt;hope it helps!</description>
      <pubDate>Tue, 25 Jul 2006 00:41:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992865#M100525</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-07-25T00:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992866#M100526</link>
      <description>Hello Hein and Sandman,&lt;BR /&gt;&lt;BR /&gt;Thanks for your reply.&lt;BR /&gt;I have tested both solutions and the results are the same. The output i got was:&lt;BR /&gt;&lt;BR /&gt;Product Name,XXX/YY       -&lt;BR /&gt;&lt;BR /&gt;The output i needed to continue my is script should be:&lt;BR /&gt;&lt;BR /&gt;Product Name,XXX/YY-Dir&lt;BR /&gt;&lt;BR /&gt;Where Dir is a Variable also.&lt;BR /&gt;&lt;BR /&gt;Am attaching my script and a file for you to check. Thanks!</description>
      <pubDate>Wed, 26 Jul 2006 01:10:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992866#M100526</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2006-07-26T01:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992867#M100527</link>
      <description>&lt;!--!*#--&gt;Your problem is that you are trying to pass the shell variable $Dir to perl.  You can't do that easily if you have to use single quotes.  It is better to pass an extra parm to your perl script.&lt;BR /&gt;&lt;BR /&gt;But if you insist, you can use massive quoting:&lt;BR /&gt;perl -pi -e "s/(^Product Name.*)$/\$1-$Dir/"&lt;BR /&gt;&lt;BR /&gt;(I had to quote the "$1".)&lt;BR /&gt;&lt;BR /&gt;To do something similar with awk, you use -v to set the variable.</description>
      <pubDate>Wed, 26 Jul 2006 01:35:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992867#M100527</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-07-26T01:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992868#M100528</link>
      <description>You're not getting the expected output because (already stated in Dennis' post) of single quotes which prevent variable expansion. Moreover using "/" within the substitution command will prevent parsing of the line owing to ambiguity if $Dir contains slashes "/".&lt;BR /&gt;&lt;BR /&gt;For example...&lt;BR /&gt;&lt;BR /&gt;Dir=/home/mydir&lt;BR /&gt;&lt;BR /&gt;and the input file contains:&lt;BR /&gt;Product Name,XXX/YY&lt;BR /&gt;&lt;BR /&gt;sed -n '/^Product Name/s/.*/&amp;amp;-$Dir/p' $FILE&lt;BR /&gt;Product Name,XXX/YY-$Dir&lt;BR /&gt;&lt;BR /&gt;notice that variable $Dir has not been expanded to its contents "/home/mydir". Now replace single quotes with double quotes and try the command again:&lt;BR /&gt;&lt;BR /&gt;sed -n "/^Product Name/s/.*/&amp;amp;-$Dir/p" $FILE&lt;BR /&gt;sed: Function /^Product Name/s/.*/&amp;amp;-/home/mydir/p cannot be parsed.&lt;BR /&gt;&lt;BR /&gt;the command errors out owing to the presence of "/" characters in $Dir variable, so change the substitution command delimiters to an unambiguous character such as "|" or ";" etc.&lt;BR /&gt;&lt;BR /&gt;sed -n "/^Product Name/s|.*|&amp;amp;-$Dir|p" $FILE&lt;BR /&gt;Product Name,XXX/YY-/home/mydir&lt;BR /&gt;&lt;BR /&gt;which gives the expected output.&lt;BR /&gt;&lt;BR /&gt;~hope it helps</description>
      <pubDate>Wed, 26 Jul 2006 05:02:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992868#M100528</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-07-26T05:02:10Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992869#M100529</link>
      <description>Pando,&lt;BR /&gt;&lt;BR /&gt;The relevant answers have already been given.&lt;BR /&gt;Some free advice though!&lt;BR /&gt;&lt;BR /&gt;Read up a little more on perl and get ready for a 'paradigm shift'. The shell script you show uses perl but really is a classic Unix shell which just happens to use perl as a tool. Might as well use awk/sed.&lt;BR /&gt;&lt;BR /&gt;Perl will happily do all the tasks in a single activation, and faster!&lt;BR /&gt;&lt;BR /&gt;For sure the two substitutes can simply be part of one command/program.&lt;BR /&gt;&lt;BR /&gt;But also the ls + awk $9 can be readily replaced by "glob": while (&amp;lt;*&amp;gt;)&lt;BR /&gt;In doing so perl will have the file names in its local variables ready to play with.&lt;BR /&gt;&lt;BR /&gt;Btw... why ask for an 'ls -l' and then extract just the name? Why not simply use 'ls'?&lt;BR /&gt;Old&amp;gt;&amp;gt; ls -l * | awk '{print $9}' |while read FILE&lt;BR /&gt;New?? For FILE in 'ls'&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enjoy!&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Jul 2006 06:52:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992869#M100529</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-07-26T06:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: problems with "/"</title>
      <link>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992870#M100530</link>
      <description>Thanks guys for the quick replies!&lt;BR /&gt;This forum is realy great!&lt;BR /&gt;</description>
      <pubDate>Thu, 27 Jul 2006 01:13:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/problems-with-quot-quot/m-p/4992870#M100530</guid>
      <dc:creator>Pando</dc:creator>
      <dc:date>2006-07-27T01:13:37Z</dc:date>
    </item>
  </channel>
</rss>

