<?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: for-do-done for 2 Fields in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658089#M102502</link>
    <description>if you put the field with spaces as the last field you won't have to delimit the fields.&lt;BR /&gt;&lt;BR /&gt;with the read command the first field is assigned to the first name, the second field to the second name, etc., with the leftover fields assigned to the last name.</description>
    <pubDate>Wed, 26 Oct 2005 08:56:12 GMT</pubDate>
    <dc:creator>curt larson_1</dc:creator>
    <dc:date>2005-10-26T08:56:12Z</dc:date>
    <item>
      <title>for-do-done for 2 Fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658086#M102499</link>
      <description>Oh scripting guru's out there. &lt;BR /&gt;&lt;BR /&gt;I need to create about 130 user accounts on a new server. The App Team have provided me with a file  containing, what will be their 5 digit uid, and a comment field containing thier full name, and location (comma delimited).&lt;BR /&gt;&lt;BR /&gt;Looks a bit like this:&lt;BR /&gt;12345   First Surname,UK/Town Name&lt;BR /&gt;&lt;BR /&gt;I'm a bit stumped as to how I'm going to achieve the following:&lt;BR /&gt;&lt;BR /&gt;useradd -u &lt;UID&gt; -g &lt;GID&gt; -d /apps/gns -s /apps/gns/bin/pfash -c  &amp;amp;lt;uid&amp;amp;gt;&amp;amp;lt;BR /&amp;amp;gt;&amp;amp;lt;BR /&amp;amp;gt;I'm not too sure how to feed the fields into a for-do-done loop. Do I also need to delimit the fields with an explicit character, as I currently have 4 fields in there delimited by a space. &amp;amp;lt;BR /&amp;amp;gt;&amp;amp;lt;BR /&amp;amp;gt;Any help would be appreciated...my head hurts. &amp;amp;lt;BR /&amp;amp;gt;&amp;amp;lt;BR /&amp;amp;gt;&lt;/GID&gt;&lt;/UID&gt;</description>
      <pubDate>Wed, 26 Oct 2005 08:34:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658086#M102499</guid>
      <dc:creator>Robin King_1</dc:creator>
      <dc:date>2005-10-26T08:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: for-do-done for 2 Fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658087#M102500</link>
      <description>something like this should work ok for you&lt;BR /&gt;&lt;BR /&gt;cat file |&lt;BR /&gt;while read uid rest&lt;BR /&gt;do&lt;BR /&gt;print "uid = $uid and rest = $rest"&lt;BR /&gt;done</description>
      <pubDate>Wed, 26 Oct 2005 08:51:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658087#M102500</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-10-26T08:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: for-do-done for 2 Fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658088#M102501</link>
      <description>easiest way is to use a while-do-done construct in my opinion, as follows:&lt;BR /&gt;&lt;BR /&gt;cat myfile | while read line&lt;BR /&gt;do&lt;BR /&gt;field1=`echo $line|cut -d, -f1`&lt;BR /&gt;field2=`echo $line|cut -d, -f2`&lt;BR /&gt;UID=`echo field1|awk {'print $1'}`&lt;BR /&gt;NameSurname=`echo field1|awk {'print $2" "$3'}`&lt;BR /&gt;LOCATION=$field2&lt;BR /&gt;&lt;BR /&gt;useradd -u $UID -g $GID -d /apps/gns -s /apps/gns/bin/pfash -c "${NameSurname},${LOCATION}" $username&lt;BR /&gt;&lt;BR /&gt;# on this statetement, you need to set the username and GID variables &lt;BR /&gt;# before executing the last command.&lt;BR /&gt;&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Oct 2005 08:51:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658088#M102501</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2005-10-26T08:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: for-do-done for 2 Fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658089#M102502</link>
      <description>if you put the field with spaces as the last field you won't have to delimit the fields.&lt;BR /&gt;&lt;BR /&gt;with the read command the first field is assigned to the first name, the second field to the second name, etc., with the leftover fields assigned to the last name.</description>
      <pubDate>Wed, 26 Oct 2005 08:56:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658089#M102502</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2005-10-26T08:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: for-do-done for 2 Fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658090#M102503</link>
      <description>Thanks all, that really helps. I find it a lot easier reading them  than contructing them. &lt;BR /&gt;</description>
      <pubDate>Wed, 26 Oct 2005 09:04:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658090#M102503</guid>
      <dc:creator>Robin King_1</dc:creator>
      <dc:date>2005-10-26T09:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: for-do-done for 2 Fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658091#M102504</link>
      <description>Hi Robin:&lt;BR /&gt;&lt;BR /&gt;Curt's suggestion is a good one for its simplicity.  I'll add another useful tip:&lt;BR /&gt;&lt;BR /&gt;The shell's IFS (Inter-Field-Separater) is designed to be leveraged for problems like this.  You can set the value of 'IFS' to any character you choose.  For example, if the colon (":") character delmited your fields:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;OLDIFS=${IFS}&lt;BR /&gt;IFS=":"&lt;BR /&gt;while read A B C&lt;BR /&gt;do&lt;BR /&gt;  echo "${A} ${B} ${C}"&lt;BR /&gt;done &amp;lt; myfile&lt;BR /&gt;IFS=${IFS}&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 26 Oct 2005 09:05:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658091#M102504</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2005-10-26T09:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: for-do-done for 2 Fields</title>
      <link>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658092#M102505</link>
      <description>Assuming you edit your file to read like this:&lt;BR /&gt;&lt;USERNAME&gt; &lt;UID&gt; &lt;GID&gt; &lt;HOME path=""&gt; &lt;SHELL&gt; &amp;lt;"COMMENT WITH SPACES"&amp;gt; &lt;BR /&gt;For example, &lt;BR /&gt;&lt;BR /&gt;/tmp/userlist:&lt;BR /&gt;user1 111 333 /home/home /shell "comment with spaces"&lt;BR /&gt;user2 222 433 /home/home /shell "comment with spaces"&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;cat /tmp/userlist | while read USERNAME UID GID HOME SHELL COMMENT&lt;BR /&gt;do&lt;BR /&gt;useradd -u $UID -g $GID -d $HOME -s $SHELL -c $COMMENT $USERNAME&lt;BR /&gt;done&lt;/SHELL&gt;&lt;/HOME&gt;&lt;/GID&gt;&lt;/UID&gt;&lt;/USERNAME&gt;</description>
      <pubDate>Wed, 26 Oct 2005 09:06:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/for-do-done-for-2-fields/m-p/3658092#M102505</guid>
      <dc:creator>Andy Torres</dc:creator>
      <dc:date>2005-10-26T09:06:55Z</dc:date>
    </item>
  </channel>
</rss>

