<?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: shell script: Add details in a file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836806#M938962</link>
    <description>Hi,&lt;BR /&gt;I guess you would like to test whether an item is already present in the itemfile or not. A small test for that could be made like this:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;ITEMFILE=/tmp/items&lt;BR /&gt;[ -r $ITEMFILE ] || touch $ITEMFILE&lt;BR /&gt;echo "Item: \c"&lt;BR /&gt;read a&lt;BR /&gt;echo "Quantity: \c"&lt;BR /&gt;read b&lt;BR /&gt;&lt;BR /&gt;# Is item already present?&lt;BR /&gt;grep "^$a"  $ITEMFILE&lt;BR /&gt;if [ "$?" = "0" ]&lt;BR /&gt;then&lt;BR /&gt;        # yes, "overwrite"&lt;BR /&gt;        OTHER_ITEMS=`grep -v "^$a" $ITEMFILE`&lt;BR /&gt;        echo "$OTHER_ITEMS\n$a $b" &amp;gt;$ITEMFILE&lt;BR /&gt;else&lt;BR /&gt;        # no, append&lt;BR /&gt;        echo $a $b &amp;gt;&amp;gt;$ITEMFILE&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;However, the original order of items is not kept.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K&lt;BR /&gt;</description>
    <pubDate>Fri, 01 Nov 2002 08:16:33 GMT</pubDate>
    <dc:creator>john korterman</dc:creator>
    <dc:date>2002-11-01T08:16:33Z</dc:date>
    <item>
      <title>shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836800#M938956</link>
      <description>I'm writing a shell script to add some details into a file. I'm not sure how to save the details into a file. I've written the script that can accept the details but how do I save them into my file?&lt;BR /&gt;&lt;BR /&gt;---------------------&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;echo "Item: \c"&lt;BR /&gt;read a&lt;BR /&gt;echo "Quantity: \c"&lt;BR /&gt;read b&lt;BR /&gt;&lt;BR /&gt;`??? &amp;gt;&amp;gt;itemFile`&lt;BR /&gt;#How do I append the details into my file?&lt;BR /&gt;&lt;BR /&gt;----------------------&lt;BR /&gt;My itemFile:&lt;BR /&gt;&lt;BR /&gt;  Item    Quantity&lt;BR /&gt; Printer     10&lt;BR /&gt; Monitor    120&lt;BR /&gt; Keyboard   120&lt;BR /&gt;&lt;BR /&gt;How can I add the item and quantity details into my itemFile?&lt;BR /&gt;</description>
      <pubDate>Thu, 31 Oct 2002 13:17:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836800#M938956</guid>
      <dc:creator>summersnowy</dc:creator>
      <dc:date>2002-10-31T13:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836801#M938957</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;read a&lt;BR /&gt;echo $a &amp;gt;&amp;gt; itemfile&lt;BR /&gt;echo "Quantity: \c"&lt;BR /&gt;read b&lt;BR /&gt;echo $b &amp;gt;&amp;gt; itemfile&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 31 Oct 2002 13:29:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836801#M938957</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2002-10-31T13:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836802#M938958</link>
      <description>Use cat and awk&lt;BR /&gt;&lt;BR /&gt;cat itemfile |awk -v printer=$a '$1 ~ /Printer/ {print $1" "printer}' &amp;gt;/tmp/itemnew&lt;BR /&gt;mv /tmp/itemnew itemfile&lt;BR /&gt;&lt;BR /&gt;This only works if there is only 1 entry called "Printer" per file.&lt;BR /&gt;&lt;BR /&gt;If you want to treat flat files as a potential 'database', then store the data in the best possible format, and then reformat it when you want to display it,.... so this example if best stored on 1 line per record (a record being a group of related variables with a unique key - basic DB management principles)&lt;BR /&gt;&lt;BR /&gt;eg. [User] [Printer] [Monitor] [Keyboard] &lt;BR /&gt;The above line format, delimited by spaces, would look like this,...&lt;BR /&gt;&lt;BR /&gt;Bob 10 120 120&lt;BR /&gt;&lt;BR /&gt;You would retrieve field 2 to get the Printer Count, and use a similar awk statement to the one above, but keyed on User.&lt;BR /&gt;&lt;BR /&gt;Share and Enjoy! Ian</description>
      <pubDate>Thu, 31 Oct 2002 13:30:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836802#M938958</guid>
      <dc:creator>Ian Dennison_1</dc:creator>
      <dc:date>2002-10-31T13:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836803#M938959</link>
      <description>Hi,&lt;BR /&gt;if you only want to append, try this:&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;ITEMFILE=/tmp/items&lt;BR /&gt;echo "Item: \c"&lt;BR /&gt;read a&lt;BR /&gt;echo "Quantity: \c"&lt;BR /&gt;read b&lt;BR /&gt;echo $a $b &amp;gt;&amp;gt;$ITEMFILE&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K.</description>
      <pubDate>Thu, 31 Oct 2002 13:35:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836803#M938959</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2002-10-31T13:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836804#M938960</link>
      <description>#!/bin/sh&lt;BR /&gt;echo "Item: \c"&lt;BR /&gt;read a&lt;BR /&gt;echo "Quantity: \c"&lt;BR /&gt;read b &lt;BR /&gt;echo $a &amp;gt;&amp;gt; file1&lt;BR /&gt;echo $b &amp;gt;&amp;gt; file2&lt;BR /&gt;paste file1 file2 &amp;gt;&amp;gt; file3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This will put the entries next to each other to easier reading</description>
      <pubDate>Thu, 31 Oct 2002 14:04:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836804#M938960</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2002-10-31T14:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836805#M938961</link>
      <description>What if I don't want to use append, what else I can do to add my details into a file?</description>
      <pubDate>Fri, 01 Nov 2002 01:53:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836805#M938961</guid>
      <dc:creator>summersnowy</dc:creator>
      <dc:date>2002-11-01T01:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836806#M938962</link>
      <description>Hi,&lt;BR /&gt;I guess you would like to test whether an item is already present in the itemfile or not. A small test for that could be made like this:&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;ITEMFILE=/tmp/items&lt;BR /&gt;[ -r $ITEMFILE ] || touch $ITEMFILE&lt;BR /&gt;echo "Item: \c"&lt;BR /&gt;read a&lt;BR /&gt;echo "Quantity: \c"&lt;BR /&gt;read b&lt;BR /&gt;&lt;BR /&gt;# Is item already present?&lt;BR /&gt;grep "^$a"  $ITEMFILE&lt;BR /&gt;if [ "$?" = "0" ]&lt;BR /&gt;then&lt;BR /&gt;        # yes, "overwrite"&lt;BR /&gt;        OTHER_ITEMS=`grep -v "^$a" $ITEMFILE`&lt;BR /&gt;        echo "$OTHER_ITEMS\n$a $b" &amp;gt;$ITEMFILE&lt;BR /&gt;else&lt;BR /&gt;        # no, append&lt;BR /&gt;        echo $a $b &amp;gt;&amp;gt;$ITEMFILE&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;However, the original order of items is not kept.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Nov 2002 08:16:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836806#M938962</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2002-11-01T08:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836807#M938963</link>
      <description>If you want to update informations inside the file then would take the solution provided by Ian. This will update the information stored in your file</description>
      <pubDate>Fri, 01 Nov 2002 09:56:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836807#M938963</guid>
      <dc:creator>Reinhard Burger</dc:creator>
      <dc:date>2002-11-01T09:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: shell script: Add details in a file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836808#M938964</link>
      <description>of course if you are adding ammounts to existing ammounts you could do it like this&lt;BR /&gt;&lt;BR /&gt;ptr=$(cat itemfile | grep Printer | awk '{print $2}')&lt;BR /&gt;mtr=$(cat itemfile | grep Monitor | awk '{print $2}')&lt;BR /&gt;kbd=$(cat itemfile | grep Keyboard | awk '{print $2}')&lt;BR /&gt;&lt;BR /&gt;echo "Enter item:\c"&lt;BR /&gt;read a&lt;BR /&gt;echo "Enter quantity:\c"&lt;BR /&gt;read b&lt;BR /&gt;if [ $a = "Printer" ]&lt;BR /&gt;then&lt;BR /&gt;((c=$b+$ptr))&lt;BR /&gt;echo sed 's/$ptr/$c/g' itemfile &amp;gt; itemfile2" &amp;gt; itemswap.sh&lt;BR /&gt;chmod +x itemswap.sh&lt;BR /&gt;./itemswap.sh&lt;BR /&gt;mv itemfile2 itemfile&lt;BR /&gt;elif [ $a = "Montitor" ]&lt;BR /&gt;then&lt;BR /&gt;((c=$b+$mtr))&lt;BR /&gt;echo "sed 's/$mtr/$c/g' itemfile &amp;gt; itemfile2" &amp;gt; itemswap.sh&lt;BR /&gt;chmod +x itemswap.sh&lt;BR /&gt;./itemswap.sh&lt;BR /&gt;mv itemfile2 itemfile&lt;BR /&gt;# do the same for any instances of the item you want to update&lt;BR /&gt;fi&lt;BR /&gt;</description>
      <pubDate>Fri, 01 Nov 2002 14:36:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-add-details-in-a-file/m-p/2836808#M938964</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2002-11-01T14:36:16Z</dc:date>
    </item>
  </channel>
</rss>

