[PLUG] (no subject)

russell-evans at qwest.net russell-evans at qwest.net
Sat Oct 18 02:24:02 UTC 2003


I'm waiting on a job to finish that doesn't require me to do anything so I have
some time.

Thank you
Russell



#/bin/sh

### VARIABLES ###

# File that contains two columns of data for parsing
INPUT_FILE=result.txt


### VARIABLES - DO NOT EDIT ###

# declare varibles
declare -a RESULT
declare -a COL1
declare -a COL2

# Create array of date in INPUT_FILE
if [ -r $INPUT_FILE ] ; then
  RESULTS=(`cat $INPUT_FILE`)
else
  exit 1
fi

# Number of elements in RESULTS array
COUNT=${#RESULTS[@]}

### FUNCTIONS ####

CREATE_COL_ARRAYS () { # create two arrays composed of each column in
INPUT_FILE
 # INPUTS: COUNT variable, count of fields in array RESULT
 # OUTPUT: COL1 array
 #	   COL2 array	     
 let x=0
 while [ $x -lt $COUNT ]  ; do
   let y=$x+1
   # Create array of first column data
   COL1[$x]=${RESULTS[$x]}
   # Create array of second column data
   COL2[$x]=${RESULTS[$y]}
   let x=$x+2
 done
} ### END CREATE_COL_ARRAYS

PROCESS_COL1 () { # Do something to COL1 array
 # INPUTS: COL1 array
 # OUTPUT:
 echo column1=\"${COL1[@]}\"			 
} ### END PROCESS_COL1

PROCESS_COL2 () { # Do something to COL2 array
 # INPUTS: COL2 array
 # OUTPUT:
 echo column2=\"${COL2[@]}\"			 
} ### END PROCESS_COL2

### MAIN ###

# Call CREATE_COL_ARRAYS to create column arrays
CREATE_COL_ARRAYS || exit 1
PROCESS_COL1 || exit 1
PROCESS_COL2 || exit 1
exit 0






On Fri, 17 Oct 2003 11:09:08 +0800, Billy Dimaculangan said:

> I have a simple question on shell scripting.
>  I have simple text file say "result.txt", which contains two columns, i
>  would get only the first column. can i do it using grep?
>  
>  
>  TY.
>  
>  
>  --
>  Billy
>  
>  
>  
>  ______________________________________________
>  PLUG mailing list
>  PLUG at lists.pdxlinux.org
>  http://lists.pdxlinux.org/mailman/listinfo/plug
>  
>  





More information about the PLUG mailing list