Sponsored Content
Top Forums Shell Programming and Scripting acessing awk array element while getline < "file" Post 302209403 by timj123 on Thursday 26th of June 2008 08:37:29 PM
Old 06-26-2008
In first part of awk script tst array is set for use in the getfile section of script. Problem I have got is, it looks like I can't use tst array while reading in and setting x array.


Code:
#!/bin/ksh
tput clear

dir=/my/dir/here/ #all files are gzip'd
ifile=/tmp/ifile
ofile=/tmp/ofile
$file=$dir$file.gz
echo "Enter the date and hour to run this script on [YYMMDDHH]: \c"
read file


#tool is run to generate $ofile here, file is semicolon delimited


/usr/bin/gzcat $file | /usr/xpg4/bin/awk '

BEGIN {
print "headers go here"
}


NR == 3 { print $2,$3"  --  "$4,$5 ; print "" ; next }

/^dise / {
        dipce = substr($2,4,1) * 1000 ; next
           }
/^LC/ {
        lec = substr($0,3,3) + dipce
        f++
        s = ""
        for ( i in arr ) { delete arr[i] }
        }
	   f {
              if ( $1 == "RRAC" ) {
                s++
                 }
                if ( s ) {
                    if ( $1 == "tsec" ) {
                       lectsec = $2 * 1
                       }
                    if ( $1 == "VAR" ) {
                        car[$2 * 1]+=$8
                        lecCar = $2 * 1
                        c[lec,lectsec,BCar] = 0
                        }
                     c[lec,lectsec,BCar]++
                     if ( c[lec,lectsec,BCar] == 8 ) {
                        car[BCar]+=$8
                        tst[lec"-"BCar]=sprintf("%5.2f",car[BCar] / 12)
                        }
                    }
                if ( $1 == "RRAC-L" ) {
                        f = "" ; next
                   }
                   }


###This section not working because I can't access###
###array tst, to "test" I tried printing tst array, but can't get it to work.

{
while (( getline < "'"$ofile"'" ) > 0 ) {
FS = "\;" 
	x[$2"-"$4]+=tst[$5"-1"] ;
        x[$5"-"$7]+=tst[$5"-2"] ;
        x[$8"-"$10]+=tst[$5"-3"];
        x[$11"-"$13]+=tst[$5"-4] ;
}
}
#####################################################
END {
for ( i in x ) { print i,x[i] }

    } '

/usr/bin/rm $ifile
/usr/bin/rm $ofile

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk: getline NOM < "-" script does not stop

Well , i have: $ cat example.dat 1 2 3 4 5 $ cat getline3.awk function getName (NOM) { printf "Enter a filename: " getline NOM < "-" # get response return NOM } BEGIN { printf ("\nREP: %s\n",getName(N)) } {print} This example works fine: (2 Replies)
Discussion started by: Klashxx
2 Replies

2. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

3. Shell Programming and Scripting

Error to "find" a matching array element in a directory

Hi, I have defined an array which holds a couple of elements which are nothing but files names. I want to find the files in a directory for the matching file name(array elements) with less than 1 day old. When I am trying to execute the code (as below), it gives an error. Your help in this... (1 Reply)
Discussion started by: mkbaral
1 Replies

4. Shell Programming and Scripting

awk's getline < "-" seems not work for pipe

Hi all, I have an gawk script to get user's input, So I use getline name < "-" (or getline name < "/dev/stdin") in my script They both work fine when my script deals with files. But it is broken for pipes. When I try "some command | my awk script", the variable name just gets an empty... (17 Replies)
Discussion started by: qiulang
17 Replies

5. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

6. Shell Programming and Scripting

Need to parse file "x" lines at a time ... awk array?

I have files that store multiple data points for the same device "vertically" and include multiple devices. It repeats a consistant pattern of lines where for each line: Column 1 is a common number for the entire file and all devices in that file Column 2 is a unique device number Column 3 is... (7 Replies)
Discussion started by: STN
7 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

9. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

10. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
getusershell(3C)					   Standard C Library Functions 					  getusershell(3C)

NAME
getusershell, setusershell, endusershell - get legal user shells SYNOPSIS
#include <unistd.h> char *getusershell(void); void setusershell(void); void endusershell(void); DESCRIPTION
The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place: /bin/bash /bin/csh /bin/jsh /bin/ksh /bin/ksh93 /bin/pfcsh /bin/pfksh /bin/pfsh /bin/sh /bin/tcsh /bin/zsh /sbin/jsh /sbin/pfsh /sbin/sh /usr/bin/bash /usr/bin/csh /usr/bin/jsh /usr/bin/ksh /usr/bin/ksh93 /usr/bin/pfcsh /usr/bin/pfksh /usr/bin/pfsh /usr/bin/sh /usr/bin/tcsh /usr/bin/zsh /usr/sfw/bin/zsh /usr/xpg4/bin/sh The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells. The setusershell() function rewinds the file or the list. The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells. RETURN VALUES
The getusershell() function returns a null pointer on EOF. BUGS
All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved. NOTES
Restricted shells should not be listed in /etc/shells. SunOS 5.11 1 Nov 2007 getusershell(3C)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy