Sponsored Content
Top Forums Shell Programming and Scripting grabbing more than one argument in a loop Post 302289487 by Intense4200 on Thursday 19th of February 2009 06:49:15 PM
Old 02-19-2009
grabbing more than one argument in a loop

Hello all I hope someone can help me. I am trying to convert something I wrote in C to bash.

But how do I go about reading more than one item at a time in a for loop?
i have been using this format for the loops in the bash script i have been building.

e.g.
Code:
for word in `cat -s sortlist2.txt`
do
    echo -e "$word\n";
done

but now i need more than one variable per pass of the loop.

here is the format of the sortlist2.txt. it is the path/name and time-stamp space separated one entry per line:
  • p2_6f_9_19_3/Eci 1063673162
    p2_6f_9_19_3/Zargon 1063679315
    p2_6f_9_19_3/Weslyn 1063681624
    p2_6j_10_8_4/Weslyn 1063681624
    p2_6k_12_11_4/Weslyn 1063681624
    p2_6l_2_16_5/Weslyn 1063681624
    p2_6f_9_19_3/Eilonwy 1063686817
    p2_6f_9_19_3/Aloof 1063686900
    p2_6f_9_19_3/Papertiger 1063688780
    p2_6f_9_19_3/Bytor 1063689879
    p2_6f_9_19_3/Ziggs 1063709714
    p2_6f_9_19_3/Tyrael_rcls 1063711697
    p2_6f_9_19_3/Cypress 1063716672
    p2_6f_9_19_3/Neuromancer 1063717200
    p2_6f_9_19_3/Endram 1063730040
    p2_6j_10_8_4/Endram 1063730040
    p2_6k_12_11_4/Endram 1063730040
    p2_6l_2_16_5/Endram 1063730040
    p2_6f_9_19_3/Bixx 1063736835
    $
The C code reads in the data and keeps the first unique entry (saved to sortlist3.txt) and puts the repeat time-stamp entries in a file (rmlist.txt) for removing those player files later.

here is the C code:
Code:
      if ((fpr = fopen("../../../parchive/rmlist.txt", "w")) == NULL)
      {
            perror("couldn't open rmlist.txt for writing.");
            return;
      }

       if ((fp = fopen("../../../parchive/sortlist2.txt", "r")) != NULL)
       {
            name = fread_word(fp);
            logo = fread_number(fp);

            if ((fpo = fopen("../../../parchive/sortlist3.txt", "w")) != NULL)
            {
                fprintf(fpo, "%s %ld\n", name, logo);                    

                for (;;)
                {
                    prev_name = name;
                    prev_logo = logo;

                    name = fread_word(fp);

                    if (name[0] == '$')
                    {
                        fprintf(fpo, "$\n");
                        break;
                    }

                    logo = fread_number(fp);

                    if (logo == prev_logo)
                    {
                        fprintf(fpr, "%s\n", name);                    
                        continue;
                    }

                    fprintf(fpo, "%s %ld\n", name, logo);                    
                }
            }
            else
            {
                perror("couldn't open sortlist3.txt for writing.");
            }
            
            fclose(fp);
            fclose(fpo);
            fclose(fpr);
        }

or is there some slick bash command(s) that can do this sorting?
I can get rid of the $ at the end of the file if needed. I just needed it for C to detect the end of the list. I thought about reading the file into two arrays, $name[] and $logo[] and then do the filtering. Possibly use the read command and a while statement? Thanks.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Argument passing using for or while loop

Hi All, My query is as below: Am basically writing a parser script. My input file has got some variables which are populated by the calling program. callig program: fun1("cat","dog","cow") input.* argument first argument second I want to write a script that should give me... (4 Replies)
Discussion started by: jisha
4 Replies

2. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies

3. UNIX for Dummies Questions & Answers

Grabbing a value from an output file

I am executing a stored proc and sending the results in a log file. I then want to grab one result from the output parameters (bolded below, 2) so that I can store it in a variable which will then be called in another script. There are more details that get printed in the beginning of the log file,... (3 Replies)
Discussion started by: hern14
3 Replies

4. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

5. Shell Programming and Scripting

Grabbing Certain Fields

ok, so a script i wrote spits out an output like the below: 2,JABABA,BV=114,CV=1,DF=-113,PCT=99.1228% as you can see, each field is separated by a comma. now, how can I get rid of the first field and ONLY show the rest of the fields. meaning, i want to get rid of the "2,", and... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

7. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

8. Shell Programming and Scripting

Expect Scripting Loop Argument Desperately Needed!

I am trying to create an Expect script that does the following: 1) Telnets to an IP address and logs in with user ID and Password 2) Issue a CLI command to the server that will output data of which I am particularly interested in a DS1 clock 'Slips' value. I want to be able to keep issuing... (0 Replies)
Discussion started by: dwightlaidler
0 Replies

9. Shell Programming and Scripting

Grabbing fields with perl

I have several .csv files containing data like this: field_1;field_2;date;comment;amount; I want to extract the 3 last fields and load them in a database. my input_file = "/dir/file.csv"; my output_file = "/dir/file.sql"; open my $csv_file, '<', $input_file or die "Can't... (1 Reply)
Discussion started by: freddie50
1 Replies

10. UNIX for Dummies Questions & Answers

Change argument in a for loop

In a "for i in *FD.CPY do" loop, I need to change .CPY to .layout so the executed command would be reclay blahFD.CPY >blahFD.layout What do I need to do to modify a copy of i to use after the > symbol? TIA (5 Replies)
Discussion started by: wbport
5 Replies
XLOGO(1)						      General Commands Manual							  XLOGO(1)

NAME
xlogo - X Window System logo SYNOPSIS
xlogo [-toolkitoption ...] DESCRIPTION
The xlogo program displays the X Window System logo. OPTIONS
Xlogo accepts all of the standard X Toolkit command line options, as well as the following: -render This option indicates that the logo should be drawn with anti-aliased edges using the RENDER extension. -sharp If -render is also specified, this forces the edges to be rendered in sharp mode, (ie. 1-bit alpha channel). -shape This option indicates that the logo window should be shaped rather than rectangular. RESOURCES
The default width and the default height are each 100 pixels. This program uses the Logo widget in the Athena widget set. It understands all of the Simple widget resource names and classes as well as: foreground (class Foreground) Specifies the color for the logo. The default is depends on whether reverseVideo is specified. If reverseVideo is specified the default is XtDefaultForeground, otherwise the default is XtDefaultBackground. shapeWindow (class ShapeWindow) Specifies that the window is shaped to the X logo. The default is False. WIDGETS
In order to specify resources, it is useful to know the hierarchy of the widgets which compose xlogo. In the notation below, indentation indicates hierarchical structure. The widget class name is given first, followed by the widget instance name. XLogo xlogo Logo xlogo ENVIRONMENT
DISPLAY to get the default host and display number. XENVIRONMENT to get the name of a resource file that overrides the global resources stored in the RESOURCE_MANAGER property. FILES
/usr/share/X11/app-defaults/XLogo specifies required resources SEE ALSO
X(7), xrdb(1) AUTHORS
Ollie Jones of Apollo Computer and Jim Fulton of the MIT X Consortium wrote the logo graphics routine, based on a graphic design by Danny Chong and Ross Chapman of Apollo Computer. X Version 11 xlogo 1.0.1 XLOGO(1)
All times are GMT -4. The time now is 06:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy