Sponsored Content
Top Forums Shell Programming and Scripting Need help with using a script variable in awk Post 302762357 by ajahuja on Monday 28th of January 2013 11:02:14 AM
Old 01-28-2013
Bug Need help with using a script variable in awk

Hi All,

Please help me with a issue in below code

Code:
head -1 sample.txt > header.txt
field_count=`head -1 sample.txt |  tr -dc '\t' | wc -c`
field_count=`expr $field_count + 1`
i=1
while [ $i -lt $field_count ]
do
j=`expr $i + 1`
field_name[$i]= `awk -F\t 'NR>=1{print ${$j}}' header.txt`
echo ${field_name[$i]}
i=`expr $i + 1`
done

I have issue with the awk statement , the last echo statement.

My requirement: to store the headers from tab delimited file into an array and print them
Note: I dont know how many headers my input file may have.

Regards,
Ajay
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing a variable into an awk script

Hello all, I'm trying to run a script of this format - for i in $(cat <file>); do grep $i <file1>|awk '{print $i, $1, $2}' It's not working - does anyone know how this can be done? Khoom (5 Replies)
Discussion started by: Khoomfire
5 Replies

2. Shell Programming and Scripting

Pass script variable value to AWK

HI all, some more mistery about AWK, I hope you can help me out: 1) I have a normal ksh script and sometime I call awk command. I set some variables in the script and I would like to use them up within AWK as well. Unfortunately AWK seems to forget all the variable values outside of its own... (1 Reply)
Discussion started by: BearCheese
1 Replies

3. Shell Programming and Scripting

How to pass a Awk variable to another script

Read parameter from a text file with one line which stored the date value like 20080831; below is the awk command I used gawk -F, "{getline RunDate;print $RunDate" text file When print $RunDate, it display 20080831 Would like to pass this variable to another script to use but not... (6 Replies)
Discussion started by: cbauw
6 Replies

4. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

5. Shell Programming and Scripting

Passing shell variable to awk script

I want to pass a shell variable to awk script : # cat file PSAPSR3 3722000 91989.25 2 98 PSAPSR7 1562000 77000.1875 5 95 PSAPUNDO 92000 4087.5625 4 96 #... (8 Replies)
Discussion started by: Reboot
8 Replies

6. Shell Programming and Scripting

Passing awk variable argument to a script which is being called inside awk

consider the script below sh /opt/hqe/hqapi1-client-5.0.0/bin/hqapi.sh alert list --host=localhost --port=7443 --user=hqadmin --password=hqadmin --secure=true >/tmp/alerts.xml awk -F'' '{for(i=1;i<=NF;i++){ if($i=="Alert id") { if(id!="") if(dt!=""){ cmd="sh someScript.sh... (2 Replies)
Discussion started by: vivek d r
2 Replies

7. UNIX for Dummies Questions & Answers

Inserting a variable in awk script

I have file input.txt: >TX1-1 Freq 55 cattctgatgaatatttgtcctttagttgttatttgt >TX1-2 Freq 19 cattctgatgaatatttgtcctttagttgttatttgt >TX1-3 Freq 17 cattctgatgaatatttgtcctttagttgttatttgt >TX1-4 Freq 6 cattctgatgaatatttgtcctttagttgttatttgt >TX1-5 Freq 6 cattctgatgaatatttgtcctttagttgttatttgt ... (5 Replies)
Discussion started by: Xterra
5 Replies

8. Shell Programming and Scripting

How to pass variable from awk script to shell?

Hi, Please need to print the Rej variable outsite the awk script which is given below...please advised how to achieve it. #!/bin/bash echo "Enter DMU Pipe delimited File name for the Feed to be validated" read DMU_File echo "Enter Pre-DMU File name for the Feed" read Predum_file ... (3 Replies)
Discussion started by: pelethangjam
3 Replies

9. Shell Programming and Scripting

Variable input to awk script

Hi guys, I wrote the following function to compare two csv files column by column. However, sometimes the input needs to be sorted before parsing it to awk. I can do this by changing the awk arguments, but I would like to make this variable if possible. The below doesn't work since the... (3 Replies)
Discussion started by: Subbeh
3 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
form_field(3CURSES)					     Curses Library Functions					       form_field(3CURSES)

NAME
form_field, set_form_fields, form_fields, field_count, move_field - connect fields to forms SYNOPSIS
cc [ flag... ] file... -lform -lcurses [ library... ] #include <form.h> int set_form_fields(FORM *form, FIELD **field); FIELD **form_fields(FORM *form); int field_count(FORM *form); int move_field(FIELD *field, int frow, int fcol); DESCRIPTION
set_form_fields() changes the fields connected to form to fields. The original fields are disconnected. form_fields() returns a pointer to the field pointer array connected to form. field_count() returns the number of fields connected to form. move_field() moves the disconnected field to the location frow, fcol in the forms subwindow. RETURN VALUES
form_fields() returns NULL on error. field_count() returns -1 on error. set_form_fields() and move_field() return one of the following: E_OK The function returned successfully. E_CONNECTED The field is already connected to a form. E_SYSTEM_ERROR System error. E_BAD_ARGUMENT An argument is incorrect E_POSTED The form is posted. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
curses(3CURSES), forms(3CURSES), attributes(5) NOTES
The header <form.h> automatically includes the headers <eti.h> and <curses.h>. SunOS 5.11 31 Dec 1996 form_field(3CURSES)
All times are GMT -4. The time now is 03:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy