Trying to create variable, value not being held


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trying to create variable, value not being held
# 1  
Old 01-12-2005
Trying to create variable, value not being held

I tried creating a variable with the awk command. The correct value is being printed to the screen; however, the variable max is not being set. The command "echo $max" is null. Any help would be greatly appreciated. Thank you.


cat test.txt:
-rw-r--r-- 1 root root 0 2005-01-12 20:51 file2005-01-12

awk -F"[ :]" '{max=$7*3600+$8*60; print max}' test.txt
75060
# 2  
Old 01-12-2005
Quote:
The correct value is being printed to the screen
Okay - that is from your print statement

Quote:
however, the variable max is not being set.
And it shouldn't be in the example since you didn't set it. Awk doesn't set it for external use - to set it externally from awk, try

Example (csh)
set max=`awk -F"[ :]" '{max=$7*3600+$8*60; print max}' test.txt`
# 3  
Old 01-13-2005
RTM,

Thank you for the quick response. The variable is now being set.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create variable from date

I have a requirement to send a trigger file (trigger_dayn.dat) to a remote server through the FTP trigger_dayn.dat - here the dayn is the day number. However the dayn is not sysdate. day 1 is from Monday 07:00.00 AM to Tuesday 06:59:59 AM and so on. So if the trigger file is generated say... (1 Reply)
Discussion started by: k_vikash
1 Replies

2. Shell Programming and Scripting

Variable to create a list

Hi all, I couldn't find an answer for this easy question, probably because the keywords I used in the search are too generic. I just want to make a list of numbers using the value of a variable, like this: NumFiles=$(ls | wc -l) for i in {1..$NumFiles}; do Say $NumFiles = 5. Bash... (3 Replies)
Discussion started by: Aquila
3 Replies

3. Shell Programming and Scripting

Held req: Awk - remove non-alpha line

Hi All, I have a file containg lines along the likes of: 18:02:00 JOB02084722 18:09:00 2010120942 18:12:04 JOB02084723 18:34:16 20100709 etc. What I want to do is remove the entire line when field 2 starts with a number so I'm left with: 18:02:00 JOB02084722 18:12:04... (8 Replies)
Discussion started by: Grueben
8 Replies

4. Shell Programming and Scripting

[bash] Executing script that is held in a variable

Hi, I'm building an installation system that uses separate data files that contain the individual characteristics of each package. Within the data file, I would like to incorporate a section that contains a bash script that is loaded into an array which is then redirected to bash to be... (13 Replies)
Discussion started by: ASGR
13 Replies

5. Programming

how to create variable for all thread in c++

hello I have this code #include <sys/types.h> #include <unistd.h> #include <iostream> #include <pthread.h> #include<cstring> using namespace std; int var1=0; void doSomething() { var1 = 5; cout<<"Do S :"<<var1<<endl; sleep(1); var1 =7; (4 Replies)
Discussion started by: vip_a1
4 Replies

6. Shell Programming and Scripting

create variable name based on another variable's value

Hello, I am needing to create a variable and assign it a value based on the value of a previosly defined variable... I am using KSH.. Example: VAR1=COMPUTER1 I need another variable like ${VAR1}_FLAG="Y", so it would actually be COMPUTER1_FLAG="Y". I will be looping through many values in... (2 Replies)
Discussion started by: benefactr
2 Replies

7. UNIX for Dummies Questions & Answers

create a new environment variable??

Hi, I have say two programs File1: echo Enter A's Value read A export A File2: while do echo $A sleep 5 done (1 Reply)
Discussion started by: pbsrinivas
1 Replies

8. Shell Programming and Scripting

Create Variable for a PATH

Hello all, I need to create a variable that contains a path to a program. I'd like to reference that variable later in the script to execute the program. Does anyone have any ideas how I can accomplish this? Thanks, Mark :) (2 Replies)
Discussion started by: mmignot
2 Replies

9. UNIX for Advanced & Expert Users

Updating a csv file held on a unix box with excel running on windows

Hi, my question is quite simple: Can I update a csv file which is held on a unix box (and which a script on the same box uses) with Microsoft Excel running in a windows environment? Or, is there a free spreadsheet package available to run in unix that will update my csv file. I know it's easy to... (5 Replies)
Discussion started by: Sn33R
5 Replies

10. Shell Programming and Scripting

Finding out the length of a string held within a variable

:confused: Does anyone know which command I can use to find out the length of a string held within a variable? (5 Replies)
Discussion started by: dbrundrett
5 Replies
Login or Register to Ask a Question