<?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: Awk scripting in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006340#M127501</link>
    <description>Hi Oktay,&lt;BR /&gt;From the sample file you posted,I found the the first occurrence of the filed "ABNA" is always exists in the line begins with "BHP".&lt;BR /&gt;So, this may help:&lt;BR /&gt;fnname=`more test|sed -n '/BHP/p'|awk '{print $8}'`&lt;BR /&gt;mv test test.${fnname}.file&lt;BR /&gt;&lt;BR /&gt;Hope it can help you!&lt;BR /&gt;&lt;BR /&gt;-ux</description>
    <pubDate>Wed, 25 Jun 2003 00:38:55 GMT</pubDate>
    <dc:creator>Fragon</dc:creator>
    <dc:date>2003-06-25T00:38:55Z</dc:date>
    <item>
      <title>Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006336#M127497</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I need to extract the first occurrence of the field ABNA which is located on line 13 of the attached file and rename the file using this field. i.e test.ABNA.file&lt;BR /&gt;&lt;BR /&gt;Could you please assist.&lt;BR /&gt;&lt;BR /&gt;Many thanks&lt;BR /&gt;Oktay</description>
      <pubDate>Tue, 24 Jun 2003 23:03:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006336#M127497</guid>
      <dc:creator>Oktay Tasdemir</dc:creator>
      <dc:date>2003-06-24T23:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006337#M127498</link>
      <description>cat test | &lt;BR /&gt;awk '/ABNA/ {print $0;exit;}' &amp;gt; test.ABNA.file</description>
      <pubDate>Tue, 24 Jun 2003 23:38:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006337#M127498</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-06-24T23:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006338#M127499</link>
      <description>Thanks for the reply,&lt;BR /&gt;The field where ABNA is located is variable and it denotes a company name which changes all the time.&lt;BR /&gt;&lt;BR /&gt;Sorry I should have been more explicit.</description>
      <pubDate>Wed, 25 Jun 2003 00:05:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006338#M127499</guid>
      <dc:creator>Oktay Tasdemir</dc:creator>
      <dc:date>2003-06-25T00:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006339#M127500</link>
      <description>yes some additional information would be helpful</description>
      <pubDate>Wed, 25 Jun 2003 00:29:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006339#M127500</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-06-25T00:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006340#M127501</link>
      <description>Hi Oktay,&lt;BR /&gt;From the sample file you posted,I found the the first occurrence of the filed "ABNA" is always exists in the line begins with "BHP".&lt;BR /&gt;So, this may help:&lt;BR /&gt;fnname=`more test|sed -n '/BHP/p'|awk '{print $8}'`&lt;BR /&gt;mv test test.${fnname}.file&lt;BR /&gt;&lt;BR /&gt;Hope it can help you!&lt;BR /&gt;&lt;BR /&gt;-ux</description>
      <pubDate>Wed, 25 Jun 2003 00:38:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006340#M127501</guid>
      <dc:creator>Fragon</dc:creator>
      <dc:date>2003-06-25T00:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006341#M127502</link>
      <description>If you prefer that line 13, the script should be:&lt;BR /&gt;fnname=`more test|sed -n '13p`|awk '{print $1}'`&lt;BR /&gt;&lt;BR /&gt;Good luck!&lt;BR /&gt;-ux</description>
      <pubDate>Wed, 25 Jun 2003 01:06:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006341#M127502</guid>
      <dc:creator>Fragon</dc:creator>
      <dc:date>2003-06-25T01:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006342#M127503</link>
      <description>Hi Oktay,&lt;BR /&gt;&lt;BR /&gt;Line 13th is fixed. Is the field 8th in 13th line fixed too?.&lt;BR /&gt;&lt;BR /&gt;In that case you can simply use these two lines.&lt;BR /&gt;&lt;BR /&gt;FIELD=$(sed -n '13p' your_file|awk '{print $8}')&lt;BR /&gt;cp your_file test.${FIELD}.file&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Wed, 25 Jun 2003 02:33:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006342#M127503</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2003-06-25T02:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006343#M127504</link>
      <description>Thanks for your replies,&lt;BR /&gt;&lt;BR /&gt;Line 13 is fixed however the 8th variable is not and depending on the file it changes?</description>
      <pubDate>Wed, 25 Jun 2003 04:09:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006343#M127504</guid>
      <dc:creator>Oktay Tasdemir</dc:creator>
      <dc:date>2003-06-25T04:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006344#M127505</link>
      <description>Hi Oktay,&lt;BR /&gt;If the 8th field in the 13th line is not fixed, how can we isolated the company name?&lt;BR /&gt;&lt;BR /&gt;You must supply some condition to detect this name in order to extract it.&lt;BR /&gt;&lt;BR /&gt;Frank.</description>
      <pubDate>Wed, 25 Jun 2003 06:16:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006344#M127505</guid>
      <dc:creator>Francisco J. Soler</dc:creator>
      <dc:date>2003-06-25T06:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006345#M127506</link>
      <description>Hi Oktay,&lt;BR /&gt;&lt;BR /&gt;try this script:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;export file_name=`awk '{if (NR==13) {for (i=1;i&amp;lt;=NF;i++) {if($i != ""){print $i; next}}}}' $1`&lt;BR /&gt;mv $1 "$file_name"&lt;BR /&gt;&lt;BR /&gt;than you can use it like &lt;BR /&gt;#&amp;lt;script_name&amp;gt; &lt;ATTACHED_FILE_NAME&gt;&lt;BR /&gt;&lt;BR /&gt;it will rename your file to ABNA&lt;BR /&gt;awk will search record number 13 for the first non-empty field(in this case ABNA), then will print this field and exit the for loop.&lt;BR /&gt;you can change the last line to &lt;BR /&gt;mv $1 test. "$file_name".txt if you like.&lt;BR /&gt;Not so short but it works.&lt;BR /&gt;&lt;BR /&gt;Have fun, ionut&lt;BR /&gt;&lt;/ATTACHED_FILE_NAME&gt;</description>
      <pubDate>Wed, 25 Jun 2003 08:31:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006345#M127506</guid>
      <dc:creator>Ionut Grigorescu_2</dc:creator>
      <dc:date>2003-06-25T08:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Awk scripting</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006346#M127507</link>
      <description>Oktay,&lt;BR /&gt;in the file you attached there is no ABNA string in line 13 but it does appear twice in line 11.&lt;BR /&gt;I'm assuming that the string you want to extract is the last non-blank field in line 11.&lt;BR /&gt;If this is the case, you can do this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;if [ ! -e $1 ]; then&lt;BR /&gt;    echo "File $1 does not exist. Exiting"&lt;BR /&gt;    exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;newname=`awk 'NR == 11 { sub("[\t ]+\015$", ""); print $NF}' $1`&lt;BR /&gt;[ ! -z $newname ] &amp;amp;&amp;amp; mv $1 test.${newname}.file&lt;BR /&gt;&lt;BR /&gt;The awk bit strips the trailing whitespace and CR from line 11 and then prints the last field.&lt;BR /&gt;If you want the second last field, change $NF to $(NF - 1)&lt;BR /&gt;&lt;BR /&gt;HTH,&lt;BR /&gt;Michael.</description>
      <pubDate>Wed, 25 Jun 2003 09:19:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/awk-scripting/m-p/3006346#M127507</guid>
      <dc:creator>Michael Kelly_5</dc:creator>
      <dc:date>2003-06-25T09:19:16Z</dc:date>
    </item>
  </channel>
</rss>

