<?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: Parsing a single file into multiple files in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020639#M97049</link>
    <description>&lt;!--!*#--&gt;Thanks to everyone for the input. They all worked fine. The scipt is now working well. Regards. &lt;BR /&gt;&lt;BR /&gt;BTW, if anyone hasn't rx'd points, let me know. I believe all w/script suggestions ahve been assigned. Thanks again.</description>
    <pubDate>Fri, 29 Dec 2006 10:51:57 GMT</pubDate>
    <dc:creator>john guardian</dc:creator>
    <dc:date>2006-12-29T10:51:57Z</dc:date>
    <item>
      <title>Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020630#M97040</link>
      <description>&lt;!--!*#--&gt;I have a file &lt;PATCHES.TXT&gt;. It has multiple patch listings within, for example line 1 might start out as "s700 10.10". Line 33 (the line number will vary with every new patch file) might start out as "s700 10.26". This file contains "listings" of files for multiple HPUX Operating Systems. I'd like to break it up so that each individual file contains only the list of patches for a particular level of OS (like s700 10.10). Can this be done w/CSPLIT or do I have to use something else? Thanks.&lt;/PATCHES.TXT&gt;</description>
      <pubDate>Thu, 28 Dec 2006 15:02:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020630#M97040</guid>
      <dc:creator>john guardian</dc:creator>
      <dc:date>2006-12-28T15:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020631#M97041</link>
      <description>Imho it would help if you could you provide a sample of the input as well as the desired output.</description>
      <pubDate>Thu, 28 Dec 2006 15:08:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020631#M97041</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-12-28T15:08:31Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020632#M97042</link>
      <description>&lt;!--!*#--&gt;No problem. Here it is...........&lt;BR /&gt;If you view the contents, it's a simple format. I just want to break it up into patch lists for each individual OS. Thanks.</description>
      <pubDate>Thu, 28 Dec 2006 15:24:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020632#M97042</guid>
      <dc:creator>john guardian</dc:creator>
      <dc:date>2006-12-28T15:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020633#M97043</link>
      <description>Hi John:&lt;BR /&gt;&lt;BR /&gt;Indeed, why not use 'csplit'.  Given this file:&lt;BR /&gt;&lt;BR /&gt;# cat ./patches&lt;BR /&gt;s700 10.10&lt;BR /&gt;PHCO_123&lt;BR /&gt;PHCO_456&lt;BR /&gt;s700 10.20&lt;BR /&gt;PHNE_12345&lt;BR /&gt;PHNE_22222&lt;BR /&gt;s800 11.0&lt;BR /&gt;PHKL_18543&lt;BR /&gt;PHSS_1234&lt;BR /&gt;PHSS_2222&lt;BR /&gt;&lt;BR /&gt;...Using:&lt;BR /&gt;&lt;BR /&gt;# csplit -s -f patchesfor ./patches '/s700 10.10/' '/s700 10.20/' '/s800 11.0/'&lt;BR /&gt;&lt;BR /&gt;...produces files named "patchesfor00", "patchesfor01", "patchesfor02" and "patchesfor03".  The first file is empty since there is nothing preceeding the first regular expression argument in the input file.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 28 Dec 2006 15:31:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020633#M97043</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-28T15:31:24Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020634#M97044</link>
      <description>How about using an awk construct which puts an OSes records into one file:&lt;BR /&gt;&lt;BR /&gt;# awk '{print $0 &amp;gt;&amp;gt; "patch."$3}' file&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Thu, 28 Dec 2006 16:04:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020634#M97044</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-12-28T16:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020635#M97045</link>
      <description>&lt;!--!*#--&gt;Hi (again) John:&lt;BR /&gt;&lt;BR /&gt;It seems that a generalized 'csplit' something like:&lt;BR /&gt;&lt;BR /&gt;# csplit -s -f patchesfor patches.txt '/^s/' '/^$/' '{35}'&lt;BR /&gt;&lt;BR /&gt;...which should create files named 'patchesfor00'... dividing them into groups that begin with "s" [for s700 or s800] and ending with a blank line as the file you provide has, should work.&lt;BR /&gt;&lt;BR /&gt;*However*, on my servers, I get an "{35} - out of range" error.  You have thirty-one (31) files to generate given your data.&lt;BR /&gt;&lt;BR /&gt;Sandman's suggestion is elegant (as his 'awk' always is!), but with your data, it doesn't behave as well as it should.&lt;BR /&gt;&lt;BR /&gt;For example, within your stanza for s800 11.23 you have variously "11.23" and "11.X".  I would think that you would still like to keep these grouped within the same output file.&lt;BR /&gt;&lt;BR /&gt;*Hence*, I'd deploy a Perl solution like this:&lt;BR /&gt;&lt;BR /&gt;# cat ./filter&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;my $fh;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    if (/^s/) {&lt;BR /&gt;        my @f = split( /[:\s]/, $_ );&lt;BR /&gt;        my $file = "$f[0]_$f[1]";&lt;BR /&gt;        open( $fh, "&amp;gt;&amp;gt;", $file ) or die "Can't open $file: $!\n";&lt;BR /&gt;    }&lt;BR /&gt;    print $fh $_;&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;&lt;BR /&gt;...Run as:&lt;BR /&gt;&lt;BR /&gt;# ./filter patches.txt&lt;BR /&gt;&lt;BR /&gt;Your output files will be produced in the directory in which you run this script.  The files will be named like "s700_20.20", "s800_11.23", etc. based upon the first two fields (s700 or s800 and the release ID following it).&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 28 Dec 2006 19:39:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020635#M97045</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-28T19:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020636#M97046</link>
      <description>Simple needs require simple solutions. I prefer the following shell script:&lt;BR /&gt;&lt;BR /&gt;FILE=/dev/null&lt;BR /&gt;while read LINE; do&lt;BR /&gt;  if [ -z "${LINE}" ]; then continue; fi&lt;BR /&gt;  if [ -z "${LINE##s*}" ]; then&lt;BR /&gt;    FILE=`echo $LINE|tr -s " " "_"`&lt;BR /&gt;  else&lt;BR /&gt;    echo $LINE &amp;gt;&amp;gt; $FILE&lt;BR /&gt;  fi&lt;BR /&gt;done &lt;PATCHES.TXT&gt;&lt;/PATCHES.TXT&gt;&lt;BR /&gt;Blank lines will be stripped.&lt;BR /&gt;Filenames will be as in JRF post</description>
      <pubDate>Fri, 29 Dec 2006 09:44:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020636#M97046</guid>
      <dc:creator>Gilles Allard</dc:creator>
      <dc:date>2006-12-29T09:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020637#M97047</link>
      <description>Hi John:&lt;BR /&gt;&lt;BR /&gt;By the way, would you please evaluate the responses you received in an earlier post, too.  Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1063457" target="_blank"&gt;https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1063457&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 29 Dec 2006 09:49:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020637#M97047</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-29T09:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020638#M97048</link>
      <description>I eval'd the earlier responses early yesterday. If they weren't updated, I'll have to redo. I assigned points and then closed that thread yesterday. I 'll recheck, though. Thanks.&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Dec 2006 10:08:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020638#M97048</guid>
      <dc:creator>john guardian</dc:creator>
      <dc:date>2006-12-29T10:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020639#M97049</link>
      <description>&lt;!--!*#--&gt;Thanks to everyone for the input. They all worked fine. The scipt is now working well. Regards. &lt;BR /&gt;&lt;BR /&gt;BTW, if anyone hasn't rx'd points, let me know. I believe all w/script suggestions ahve been assigned. Thanks again.</description>
      <pubDate>Fri, 29 Dec 2006 10:51:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020639#M97049</guid>
      <dc:creator>john guardian</dc:creator>
      <dc:date>2006-12-29T10:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020640#M97050</link>
      <description>Hi John:&lt;BR /&gt;&lt;BR /&gt;The thread I would like you to look at dates from September:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1063457" target="_blank"&gt;https://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1063457&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Happy New Year!&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 29 Dec 2006 10:59:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020640#M97050</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-12-29T10:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020641#M97051</link>
      <description>On closer inspection I agree with JRF that the awk construct I posted earlier will not do the job owing to the variable format of field three in the input file. Besides I used a small portion of the sample input you had provided to test my script. So I used the entire input file provided, built another script that provides the desired output. And thank you for those words JRF, coming from the master himself :)&lt;BR /&gt;&lt;BR /&gt;Give the awk script below a try:&lt;BR /&gt;&lt;BR /&gt;# awk -F" +" '{if($0!~"^ " &amp;amp;&amp;amp; $0!~"^$")p=z[split($2,z,":")-1];print $0&amp;gt;&amp;gt;"patch."p}' file&lt;BR /&gt;&lt;BR /&gt;~cheers</description>
      <pubDate>Fri, 29 Dec 2006 12:27:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020641#M97051</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-12-29T12:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a single file into multiple files</title>
      <link>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020642#M97052</link>
      <description>Thanks guys. All input appreciated. I'm off and running now. See you all in the New Year!</description>
      <pubDate>Fri, 29 Dec 2006 13:34:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/parsing-a-single-file-into-multiple-files/m-p/5020642#M97052</guid>
      <dc:creator>john guardian</dc:creator>
      <dc:date>2006-12-29T13:34:41Z</dc:date>
    </item>
  </channel>
</rss>

