<?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: Script challenged: print lines with \ and spaces in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471087#M704191</link>
    <description>John,&lt;BR /&gt;sorry, but perhaps even better ;-)&lt;BR /&gt;&lt;BR /&gt;paste -s -d"," $filename&lt;BR /&gt;&lt;BR /&gt;Regards</description>
    <pubDate>Wed, 26 Jan 2005 04:55:20 GMT</pubDate>
    <dc:creator>Peter Godron</dc:creator>
    <dc:date>2005-01-26T04:55:20Z</dc:date>
    <item>
      <title>Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471082#M704186</link>
      <description>I'm just not getting it.   I'd appreciate any help.  I'm attempting to write a posix script that will convert a file with a few lines into one, comma delimited line so I can load it to a database.  The issue is the tricky \ and space characters ending in unwanted escaping, etc. &lt;BR /&gt;&lt;BR /&gt;example:&lt;BR /&gt;includes file contains:&lt;BR /&gt;&lt;BR /&gt;D:\AUL Scripts&lt;BR /&gt;D:\OVOW_patches&lt;BR /&gt;D:\HP OpenView\Data\Databases\backup&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I'd like write something in posix that will&lt;BR /&gt;cat these and convert to:&lt;BR /&gt;&lt;BR /&gt;D:\AUL Scripts,D:\OVOW_patches,D:\HP OpenView\Data\Databases\backup&lt;BR /&gt;&lt;BR /&gt;thanks!  points to everyone!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jan 2005 20:19:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471082#M704186</guid>
      <dc:creator>John J Read</dc:creator>
      <dc:date>2005-01-25T20:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471083#M704187</link>
      <description>I'm sure some one else would give you a &lt;BR /&gt;better one, but how about this:&lt;BR /&gt;&lt;BR /&gt;-----------&lt;BR /&gt;while read -r line&lt;BR /&gt;do&lt;BR /&gt;newline="'$line'"&lt;BR /&gt;echo $newline,&lt;BR /&gt;done &amp;lt; EXAMPLE_FILE  | xargs echo | sed 's/, /,/g' | sed 's/,$//g'&lt;BR /&gt;--------------&lt;BR /&gt;&lt;BR /&gt;Replace EXAMPLE_FILE by your input file name.&lt;BR /&gt;&lt;BR /&gt;- Biswajit&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jan 2005 21:03:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471083#M704187</guid>
      <dc:creator>Biswajit Tripathy</dc:creator>
      <dc:date>2005-01-25T21:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471084#M704188</link>
      <description>Well, if you insist upon an all shell solution (awk or Perl would be easier):&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;PREV=""&lt;BR /&gt;typeset -i KNT=0&lt;BR /&gt;while read X&lt;BR /&gt;  do&lt;BR /&gt;    if [[ ${KNT} -ne 0 ]]&lt;BR /&gt;      then&lt;BR /&gt;        echo "${PREV},\c"&lt;BR /&gt;      fi&lt;BR /&gt;     ((KNT += 1))&lt;BR /&gt;     PREV="${X}"&lt;BR /&gt;  done&lt;BR /&gt;echo "${PREV}"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Invoke it like this:&lt;BR /&gt;&lt;BR /&gt;myscript.sh &amp;lt; infile &amp;gt; outfile&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jan 2005 21:10:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471084#M704188</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-01-25T21:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471085#M704189</link>
      <description>I greatly appreciate your responses but both solutions above miss by a little bit.  Also, I'd be happy to try Perl or Awk.  &lt;BR /&gt;&lt;BR /&gt;In the first solution, note the /b in the last line ...\backup is being interpreted by the shell as "backup one space".  If the file were to begin with \n " interpreted as new-line" then the whole thing fails. &lt;BR /&gt;&lt;BR /&gt;while read -r line&lt;BR /&gt;do&lt;BR /&gt;newline="'$line'"&lt;BR /&gt;echo $newline,&lt;BR /&gt;done &amp;lt; ./includes | xargs echo | sed 's/, /,/g' | sed 's/,$//g'&lt;BR /&gt;&lt;BR /&gt;D:\AUL Scripts,D:\OVOW_patches,D:\HP OpenView\Data\Databaseackup   &amp;lt;- note the missing "b". &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;In the second solution the backslashes are lost. &lt;BR /&gt;&lt;BR /&gt;./jj &amp;lt; ./includes&lt;BR /&gt;D:AUL Scripts,D:OVOW_patches,D:HP OpenViewDataDatabasesbackup&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Feel free to write in alternate languages.  It's time I buckle down and get better at Perl. Shell has usually gotten the job done but I always know it would have been easier if I was better at Perl. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 25 Jan 2005 22:47:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471085#M704189</guid>
      <dc:creator>John J Read</dc:creator>
      <dc:date>2005-01-25T22:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471086#M704190</link>
      <description>John,&lt;BR /&gt;a oneliner which should work:&lt;BR /&gt;&lt;BR /&gt;paste -s $filename | sed "1,$ s/        D:/,D:/g" &amp;gt; $newfilename&lt;BR /&gt;&lt;BR /&gt;Please make sure the command is on one line!&lt;BR /&gt;&lt;BR /&gt;The paste -s merges the lines, seperated I believe by tabs, and the sed replaces the tabs with commas.&lt;BR /&gt;&lt;BR /&gt;Please let us know how you get on.&lt;BR /&gt;Regards</description>
      <pubDate>Wed, 26 Jan 2005 04:50:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471086#M704190</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-01-26T04:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471087#M704191</link>
      <description>John,&lt;BR /&gt;sorry, but perhaps even better ;-)&lt;BR /&gt;&lt;BR /&gt;paste -s -d"," $filename&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Wed, 26 Jan 2005 04:55:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471087#M704191</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-01-26T04:55:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471088#M704192</link>
      <description>Very cool!  Both of the "paste" commands above do the trick!  Thanks!  This gets me what I need.  Shell comes through again!Still going to dedicate some time to Perl.&lt;BR /&gt;&lt;BR /&gt;thanks everyone..</description>
      <pubDate>Wed, 26 Jan 2005 09:23:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471088#M704192</guid>
      <dc:creator>John J Read</dc:creator>
      <dc:date>2005-01-26T09:23:31Z</dc:date>
    </item>
    <item>
      <title>Re: Script challenged: print lines with \ and spaces</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471089#M704193</link>
      <description>&lt;BR /&gt;Here are (two of many) perl solution:&lt;BR /&gt;&lt;BR /&gt;perl -e 'while (&amp;lt;&amp;gt;){ chop; $line.=$_."," } chop $line; print "$line\n"' x&lt;BR /&gt;&lt;BR /&gt;D:\AUL Scripts,D:\OVOW_patches,D:\HP OpenView\Data\Databases\backup&lt;BR /&gt;&lt;BR /&gt;- Simple loop over input into default $_&lt;BR /&gt;- append each $_ to lien being build, adding a comma.&lt;BR /&gt;- chop of final comma and print.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;perl -e 'local $/; $_=&amp;lt;&amp;gt;; s/\n/,/g;print' x&lt;BR /&gt;&lt;BR /&gt;This clears a special variable to make perl go into 'slurp' mode reading the whoel file into a string. Now replace every newline with a comma and print.&lt;BR /&gt;&lt;BR /&gt;fwiw,&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Jan 2005 09:51:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/script-challenged-print-lines-with-and-spaces/m-p/3471089#M704193</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2005-01-26T09:51:30Z</dc:date>
    </item>
  </channel>
</rss>

