awk returns an integer?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk returns an integer?
# 1  
Old 02-23-2009
awk returns an integer?

I need to extract a value from a text file into a ksh script, and change the last two letters to "00". awk gets the right value (2500 in this example), but the variable has no value.

I use the following command:
StartTime=expr nawk 'NR==20 {print $11;exit}' $New_FILE
echo 1 $StartTime mytime
$StartTime=`echo $StartTime | sed -n -e "s/30/00/" -e "p"`

where $New_FILE is the text file name.

What I get is:
2500
,1 mytime
Main[46]: =: not found

Thanks for your help,
Iliklev
# 2  
Old 02-23-2009
Perhaps you can better post your input file and the desired output instead of a solution that doesn't work.

Regards
# 3  
Old 02-23-2009
sure.
Here is the input file (without the header lines).
I need to extract a parameter $11 from line 20 and use it as a variable $StartTime in the code. (In this file it is 2500)

NOMV TV ETIQUETTE NI NJ NK (DATE-O h m s) IP1 IP2 IP3 DEET NPAS DTY G IG1 IG2 IG3 IG4

0- HSO3 P AURV1.31WFLX 160 210 1 20070601 000000 0 2500 0 900 100 R16 N 150 200 23936 37973
1- HPXA P AURV1.31WFLX 160 210 1 20070601 000000 0 2500 0 900 100 R16 N 150 200 23936 37973
2- RPXA P AURV1.31WFLX 160 210 1 20070601 000000 0 2500 0 900 100 R16 N 150 200 23936 37973
3- SO4= P AURV1.31WFLX 160 210 1 20070601 000000 0 2500 0 900 100 R16 N 150 200 23936 37973
# 4  
Old 02-23-2009
Hopely is this what you mean, it assigns the 11th field of line 20 to the variable StartTime:

Code:
StartTime=$(awk 'NR==20{print $11;exit}' file)

Regards
# 5  
Old 02-23-2009
Thanks Franklin52

That did the trick
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove carriage returns from awk output

I'm on Linux version 2.6.32-696.3.1.el6.x86_64, using the Ksh shell. I'm working with the input file: John Daggett, 341 King Road, Plymouth MA Alice Ford, 22 East Broadway, Richmond VA Orville Thomas, 11345 Oak Bridge Road, Tulsa OK Terry Kalkas, 402 Lans Road, Beaver Falls PA Eric Adams,... (2 Replies)
Discussion started by: prooney
2 Replies

2. Shell Programming and Scripting

Awk script returns nothing

HSLIST=$1 LFILE=$2 STRING=$3 awk 'BEGIN { while((getline < "'${HSLIST}'")>0) S FS="\n"; RS="}\n" } /servicestatus {/ && /service_description='${STRING}'/ { for(X in D) delete D; for(N=2; N<=NF; N++) { split($N, A, "="); (4 Replies)
Discussion started by: SkySmart
4 Replies

3. Shell Programming and Scripting

Word Count (wc -w) returns a non-integer value

Hi, Why is it I cannot compare the return value of 'wc -w' to an integer? Please see code below: a="x y z" b=`echo ${a} | wc -w` if ; then echo "less than 4" fi when I try to run error always happen (: integer expression expected) - error is on the if statement Please... (1 Reply)
Discussion started by: h0ujun
1 Replies

4. Shell Programming and Scripting

Calculating an integer with awk

I would like to extract a number from $0 and calculate if it can be devided by 25. Though the number can also be less then 25 or bigger than 100. How do i extract the number and how can the integer be calculated? String: "all_results">39</span>I am looking for the number between "all_results"> ... (5 Replies)
Discussion started by: sdf
5 Replies

5. Shell Programming and Scripting

awk print last line returns empty string

hello I have a file with lines of info separated with "|" I want to amend the second field of the last line, using AWK my problem is with geting awk to return the last line this is what I am using awk 'END{ print $0 }' myFile but I get an empty result I tried the... (13 Replies)
Discussion started by: TasosARISFC
13 Replies

6. Shell Programming and Scripting

for loop returns more output with awk

I need to get total number of hdisk not assigned to any VGs. PDC # lspv |grep None |awk '{print $1}' |wc 131 131 1099 So, it shows 131 hdisks. I need to look at the individual hdisk fget_config info like below: PDC # fget_config -Av |grep hdisk230 hdisk230 dac1 229... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

7. Emergency UNIX and Linux Support

Adding carriage returns to file using sed/awk

Hello, I need help adding carriage returns at specific intervals (say 692 characters) to a text file that's one continous string. I'm working in AIX5.3. Any quick help is appreciated. Thanks! (2 Replies)
Discussion started by: bd_joy
2 Replies

8. Shell Programming and Scripting

awk returns null?

hi i try to check if awk returns null and i dont know how it's works this is the command set EndByC = `ls -l $base | awk '/.c$/ {print $9}'` if ($EndByC=="") then #check if ther is XXX.c directory echo Sorry ther is no XXX.c folder "in" $base path echo the XXX.c folder is necessary... (6 Replies)
Discussion started by: frenkelor
6 Replies

9. Shell Programming and Scripting

counting non integer number in awk

Hi, I am having the following number in the file tmp 31013.004 20675.336 43318.190 30512.926 48992.559 277893.111 41831.330 8749.113 415980.576 28273.054 I want to add these numbers, I am using following script awk 'END{print s}{s += $1}' tmp its giving answer 947239 which is correct,... (3 Replies)
Discussion started by: chaitubek
3 Replies

10. UNIX for Dummies Questions & Answers

awk or grep for integer only

how do you print the lines that contain integers only, using grep or awk? thanks , apalex ------------------ this file below: qwerty 01234 asdfgh 01234 qwer12 asdf05 will be: 01234 01234 qwer12 asdf05 (5 Replies)
Discussion started by: apalex
5 Replies
Login or Register to Ask a Question