Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Awk: use variable defined in begin Post 303009434 by Scrutinizer on Thursday 14th of December 2017 11:23:21 AM
Old 12-14-2017
Oww that is right,
Try:
Code:
FNR==1{ incr=NF/12 }

If NF is the same for every line in the file

In the BEGIN section NF is not yet initialized..

And remove the NR>1 condition

So:
Code:
awk ' FNR==1{ incr=NF/12 } { print incr }'

 

10 More Discussions You Might Find Interesting

1. Linux

environment variable is not defined

moved to correct thread (0 Replies)
Discussion started by: alien12
0 Replies

2. Shell Programming and Scripting

Replace variable with a user defined variable

I have a file that has a list of entries in a column x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl >... (1 Reply)
Discussion started by: ce124
1 Replies

3. Shell Programming and Scripting

Force Input in User Defined Variable

In a line such as: echo -n "How many days back would you like to check? "; read days How can I ensure that the user has a.) entered a number between 1-30 (not 0 or 31+) and b.) has not just hit enter (ie set it to "") and if it's entered wrong, how do I start the if statement over? I... (10 Replies)
Discussion started by: earnstaf
10 Replies

4. Shell Programming and Scripting

Finding Variable Value defined in a Script

Hi , I had a script in which there is a variable $LOG defined and I want to check where that variable is getting value from, is there a way I can check for that variable and it's value if it is defined in some other script function or script . I checked using command env and also export... (1 Reply)
Discussion started by: somu_june
1 Replies

5. Shell Programming and Scripting

Unable to add user defined variable

Hi, I have a user defined variable _TIME1=xxx I am using awk command for pattern matching. cat $_LOCATION/catalina.txt | awk '/^`$_TIME1`:??:??/' It not taking the value of $_TIME! eg:I am using the command to get all the patter from 12:00:00 to 12:59:59 The user defined variable... (2 Replies)
Discussion started by: ahamed
2 Replies

6. UNIX for Dummies Questions & Answers

Finding WHERE an environment variable is defined.

HI. I had an environment variable defined in my .bash_profile file and I deleted it. I opened a new terminal and looked inside .bash_profile and it's not there but when I type printenv MYCONFIG it reutrns what the value used to be in my .bash_profile still!! I did a grep for MYCONFIG and... (6 Replies)
Discussion started by: dissectcode
6 Replies

7. Shell Programming and Scripting

Defined Variable from text file

Hi Guys, I have one text file ABC.txt...It have 3 lines List=/home/klk/dir/ABC.txt Leajnk123 KJUHIO1234 IJOKIJ7676 I want use as different variable of each line.Just like X=firstline Y=Secound Line Z=Third Line (4 Replies)
Discussion started by: asavaliya
4 Replies

8. Shell Programming and Scripting

Question about awk - create a user-defined variable

Hi, guys, The content of file is below (from <UNIX® Shells by Example Fourth Edition>): My code is below: gawk -F'' ' { OFS = "****"; $3 = "(904)"; $8 = $5 + $6 + $7; print } ' lab3.data The result is below: So, where is the $1? Why is the variable $8 located at the wired position? (3 Replies)
Discussion started by: franksunnn
3 Replies

9. Shell Programming and Scripting

How do I get variable defined in BASH subshell outside?

I'm a BASH shell user (relatively new) I need to get a variable calculated in a subshell, outside the subshell, when it completes. I can do it, by writing the variable into a file, and then reading the file again when outside the subshell. I've tried lots of things from exporting to environmental... (3 Replies)
Discussion started by: goreilly
3 Replies

10. Shell Programming and Scripting

Usage of a variable in awk BEGIN

Hi, diffcount=`awk 'BEGIN { while ( getline < "/scripts/matt/text.server1.reference" ) { arr++ } } { if (!( $0 in arr ) ) { print } }' $TMPDIR/$(basename $0 .sh) | wc -l` if ]; then OK="OK - No change in the interfaces status" elif ]; then DIFF=`awk 'BEGIN {... (4 Replies)
Discussion started by: nms
4 Replies
CUBRID_NEXT_RESULT(3)							 1						     CUBRID_NEXT_RESULT(3)

cubrid_next_result - Get result of next query when executing multiple SQL statements

SYNOPSIS
bool cubrid_next_result (resource $result) DESCRIPTION
The cubrid_next_result(3) function is used to get results of next query if multiple SQL statements are executed and CUBRID_EXEC_QUERY_ALL flag is set upon cubrid_execute(3). PARAMETERS
o $result -$result comes from a call to cubrid_execute(3) RETURN VALUES
TRUE, when process is successful. FALSE, when process is unsuccessful. EXAMPLES
Example #1 cubrid_next_result(3) example <?php $conn = cubrid_connect("127.0.0.1", 33000, "demodb", "dba"); $sql_stmt = "SELECT * FROM code; SELECT * FROM history WHERE host_year=2004 AND event_code=20281"; $res = cubrid_execute($conn, $sql_stmt, CUBRID_EXEC_QUERY_ALL); get_result_info($res); cubrid_next_result($res); get_result_info($res); function get_result_info($req) { printf(" ------------ get_result_info -------------------- "); $row_num = cubrid_num_rows($req); $col_num = cubrid_num_cols($req); $column_name_list = cubrid_column_names($req); $column_type_list = cubrid_column_types($req); $column_last_name = cubrid_field_name($req, $col_num - 1); $column_last_table = cubrid_field_table($req, $col_num - 1); $column_last_type = cubrid_field_type($req, $col_num - 1); $column_last_len = cubrid_field_len($req, $col_num - 1); $column_1_flags = cubrid_field_flags($req, 1); printf("%-30s %d ", "Row count:", $row_num); printf("%-30s %d ", "Column count:", $col_num); printf(" "); printf("%-30s %-30s %-15s ", "Column Names", "Column Types", "Column Len"); printf("------------------------------------------------------------------------------ "); $size = count($column_name_list); for($i = 0; $i < $size; $i++) { $column_len = cubrid_field_len($req, $i); printf("%-30s %-30s %-15s ", $column_name_list[$i], $column_type_list[$i], $column_len); } printf(" "); printf("%-30s %s ", "Last Column Name:", $column_last_name); printf("%-30s %s ", "Last Column Table:", $column_last_table); printf("%-30s %s ", "Last Column Type:", $column_last_type); printf("%-30s %d ", "Last Column Len:", $column_last_len); printf("%-30s %s ", "Second Column Flags:", $column_1_flags); printf(" "); } ?> The above example will output: ------------ get_result_info -------------------- Row count: 6 Column count: 2 Column Names Column Types Column Len ------------------------------------------------------------------------------ s_name char 1 f_name varchar 6 Last Column Name: f_name Last Column Table: code Last Column Type: varchar Last Column Len: 6 Second Column Flags: ------------ get_result_info -------------------- Row count: 4 Column count: 5 Column Names Column Types Column Len ------------------------------------------------------------------------------ event_code integer 11 athlete varchar 40 host_year integer 11 score varchar 10 unit varchar 5 Last Column Name: unit Last Column Table: history Last Column Type: varchar Last Column Len: 5 Second Column Flags: not_null primary_key unique_key SEE ALSO
cubrid_execute(3). PHP Documentation Group CUBRID_NEXT_RESULT(3)
All times are GMT -4. The time now is 04:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy