<?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 awk/sed/tr problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889990#M704909</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a file of the format:&lt;BR /&gt;&lt;BR /&gt;start: 1001&lt;BR /&gt;12&lt;BR /&gt;32&lt;BR /&gt;34&lt;BR /&gt;35&lt;BR /&gt;36&lt;BR /&gt;&lt;BR /&gt;start: 1002&lt;BR /&gt;asd&lt;BR /&gt;we&lt;BR /&gt;23&lt;BR /&gt;&lt;BR /&gt;I want to format this output to read:&lt;BR /&gt;start: 1001, 12, 32, 34, 35, 36&lt;BR /&gt;start: 1002, asd, we, 23&lt;BR /&gt;&lt;BR /&gt;..so in other words remove line feeds and use the keywords start,and a blank line to delimit the start and end of a record (as you can see these records are of variable length. So I know I can remove line feeds with things like tr (tr -d '\n' &amp;lt; file.txt), but can't work out how I can get this to work with record delimiters. I tried stuff in awk and sed but can't work this one out - any ideas?</description>
    <pubDate>Mon, 07 Mar 2005 11:58:38 GMT</pubDate>
    <dc:creator>alec pringle</dc:creator>
    <dc:date>2005-03-07T11:58:38Z</dc:date>
    <item>
      <title>awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889990#M704909</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a file of the format:&lt;BR /&gt;&lt;BR /&gt;start: 1001&lt;BR /&gt;12&lt;BR /&gt;32&lt;BR /&gt;34&lt;BR /&gt;35&lt;BR /&gt;36&lt;BR /&gt;&lt;BR /&gt;start: 1002&lt;BR /&gt;asd&lt;BR /&gt;we&lt;BR /&gt;23&lt;BR /&gt;&lt;BR /&gt;I want to format this output to read:&lt;BR /&gt;start: 1001, 12, 32, 34, 35, 36&lt;BR /&gt;start: 1002, asd, we, 23&lt;BR /&gt;&lt;BR /&gt;..so in other words remove line feeds and use the keywords start,and a blank line to delimit the start and end of a record (as you can see these records are of variable length. So I know I can remove line feeds with things like tr (tr -d '\n' &amp;lt; file.txt), but can't work out how I can get this to work with record delimiters. I tried stuff in awk and sed but can't work this one out - any ideas?</description>
      <pubDate>Mon, 07 Mar 2005 11:58:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889990#M704909</guid>
      <dc:creator>alec pringle</dc:creator>
      <dc:date>2005-03-07T11:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889991#M704910</link>
      <description>Someone will probably have a prettier way of doing it, but here is one way:&lt;BR /&gt;&lt;BR /&gt;#!/usr/local/bin/perl&lt;BR /&gt;foreach $line(`cat input`)&lt;BR /&gt;{&lt;BR /&gt;  $line =~ s/\s+$//;&lt;BR /&gt;  if ($line eq "") { next; }&lt;BR /&gt;  if(grep/start/,$line)&lt;BR /&gt;  {&lt;BR /&gt;    print "\n";&lt;BR /&gt;    print "$line, ";&lt;BR /&gt;  }&lt;BR /&gt;  else { print "$line, "; }&lt;BR /&gt;}&lt;BR /&gt;print "\n";</description>
      <pubDate>Mon, 07 Mar 2005 12:27:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889991#M704910</guid>
      <dc:creator>Ken Penland_1</dc:creator>
      <dc:date>2005-03-07T12:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889992#M704911</link>
      <description>alec,&lt;BR /&gt;&lt;BR /&gt;Assuming your data contained in /tmp/file you can use awk as follows.&lt;BR /&gt;&lt;BR /&gt;awk -F":" '{if($1=="start") \&lt;BR /&gt;        printf "\n%s",$0 \&lt;BR /&gt;        else \&lt;BR /&gt;        printf " %s",$0 \&lt;BR /&gt;        }' /tmp/file&lt;BR /&gt;&lt;BR /&gt;Hope this helps. Please take care of newline after each statement.</description>
      <pubDate>Mon, 07 Mar 2005 12:27:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889992#M704911</guid>
      <dc:creator>Rajeev Tyagi</dc:creator>
      <dc:date>2005-03-07T12:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889993#M704912</link>
      <description>#!/bin/ksh&lt;BR /&gt;newline=""&lt;BR /&gt;infile=./testfile&lt;BR /&gt;outfile=./test.out&lt;BR /&gt;&amp;gt; $outfile&lt;BR /&gt;&lt;BR /&gt;cat $infile | while read line&lt;BR /&gt;do&lt;BR /&gt;   if [[ -z $line ]] ; then&lt;BR /&gt;      newline="TRUE"&lt;BR /&gt;   elif echo "${line}" | grep "^start" &amp;gt; /dev/null ; then&lt;BR /&gt;      if [[ $newline = "TRUE" ]] ; then&lt;BR /&gt;         echo &amp;gt;&amp;gt; $outfile&lt;BR /&gt;      fi&lt;BR /&gt;      echo "${line}\c" &amp;gt;&amp;gt; $outfile&lt;BR /&gt;      newline=""&lt;BR /&gt;   else&lt;BR /&gt;      echo ", ${line}\c" &amp;gt;&amp;gt; $outfile&lt;BR /&gt;      newline=""&lt;BR /&gt;   fi&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Mon, 07 Mar 2005 12:30:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889993#M704912</guid>
      <dc:creator>Gordon  Morrison_1</dc:creator>
      <dc:date>2005-03-07T12:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889994#M704913</link>
      <description>#!/bin/sh&lt;BR /&gt;&lt;BR /&gt;awk '&lt;BR /&gt;{&lt;BR /&gt; if($1=="start:") { printf("\n%s",$0);}&lt;BR /&gt; else { if(length($0) &amp;gt; 1) printf(", %s",$0);}&lt;BR /&gt;}&lt;BR /&gt;END{printf("\n");}' &lt;YOURFILE&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;Jean-Luc&lt;/YOURFILE&gt;</description>
      <pubDate>Mon, 07 Mar 2005 12:37:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889994#M704913</guid>
      <dc:creator>Jean-Luc Oudart</dc:creator>
      <dc:date>2005-03-07T12:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889995#M704914</link>
      <description>Alec,&lt;BR /&gt;as a sh shell script (assuming your data is in a.lis)&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;while read record&lt;BR /&gt;do&lt;BR /&gt;if [ -z "$record" ]&lt;BR /&gt;then&lt;BR /&gt;echo $data&lt;BR /&gt;data=""&lt;BR /&gt;else&lt;BR /&gt;if [ `expr substr "$record" 1 6` = "start:" ]&lt;BR /&gt;then&lt;BR /&gt;data="$record"&lt;BR /&gt;else&lt;BR /&gt;data="$data,$record"&lt;BR /&gt;fi&lt;BR /&gt;fi&lt;BR /&gt;done &amp;lt; a.lis&lt;BR /&gt;&lt;BR /&gt;To extract data between reg. expressions use:&lt;BR /&gt;sed -n '/reg1/,/reg2/p' &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;</description>
      <pubDate>Mon, 07 Mar 2005 12:40:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889995#M704914</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-03-07T12:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889996#M704915</link>
      <description>this worked for me&lt;BR /&gt;&lt;BR /&gt;cat yourFile | awk '&lt;BR /&gt;/^start/ { printf("%s", $0); next;}&lt;BR /&gt;NF &amp;gt; 0  {printf(", %s", $0); next;}&lt;BR /&gt;{printf("\n"); #blankline&lt;BR /&gt;}'&lt;BR /&gt;</description>
      <pubDate>Mon, 07 Mar 2005 12:49:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889996#M704915</guid>
      <dc:creator>c_51</dc:creator>
      <dc:date>2005-03-07T12:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: awk/sed/tr problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889997#M704916</link>
      <description>Hi, thanks for all your help.  I used the awk method in the end as it was closest to way I was trying to do it.</description>
      <pubDate>Mon, 07 Mar 2005 12:53:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-sed-tr-problem/m-p/4889997#M704916</guid>
      <dc:creator>alec pringle</dc:creator>
      <dc:date>2005-03-07T12:53:16Z</dc:date>
    </item>
  </channel>
</rss>

