How to evaluate expression under awk?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to evaluate expression under awk?
# 1  
Old 08-18-2017
How to evaluate expression under awk?

I have to display only those subscribers which are in "unconnected state" and the date is 90 days older than today's date.

Below command is used for this purpose:
Code:
cat vfsubscriber_20170817.csv | sed -e 's/^"//' -e '1d' | \
nawk -F '",' '{if ( (substr($11,2,4) == 2017) && ( substr($11,2,8) -lt $dm )&&($9=="\"unconnected") ) print $1,substr($11,2,8),$dm}' dm=$(perl -e 'use
POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*24*90);') > ${EXTRACT_FILE}

Problem is that this expression is not getting evaluated : `( substr($11,2,8) -lt $dm )`
Code:
dm=$(perl -e 'use
POSIX qw(strftime); print strftime "%Y%m%d",localtime(time()- 3600*24*90);')

results into " 20170520 " which is correct.

Please help me to get this expression evaluated and compared correctly in the command.

Last edited by vbe; 08-18-2017 at 08:02 AM.. Reason: code tags please
# 2  
Old 08-18-2017
Duplicate post. Continue here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Evaluate Expression within awk

I want to create a conditional expression string and pass in an awk script. My script is as below... comm="\$3 == "hello"" awk -F "^T" -v command="${comm}" ' { if ( command ) { print "hye" } }' testBut the statement "if ( command )" always evaluates to true which is not... (5 Replies)
Discussion started by: Saikat123
5 Replies

2. Shell Programming and Scripting

How to evaluate a variable name on LHS of expression?

I am trying to write a simple function to select values from a database and assign them to variables. It can have any number of arguments sent into it, and I want to assign the value retrieved to a different variable name for each argument sent in. So my code looks something like this: ... (6 Replies)
Discussion started by: DJR
6 Replies

3. Shell Programming and Scripting

awk print expression

Hi All, I have a doubt in awk print exp. Where in some awk commands have seen a digit 1 appended at the end of the awk ,didnt remember the command . like .. cat file |awk '{print }1' Could some one help in understanding these cases where we use them. Regards, Ganesh, (2 Replies)
Discussion started by: rmkganesh
2 Replies

4. Shell Programming and Scripting

awk regular expression

Hello, I have big files which I wanna filter them based on first column. first column should be one of these strings: chr2L || chr2R || chr3L || chr3R || chr4 || chrX and something like chr2Lh or chrY or chrM3L is not accepted. I used the following command: awk '{ if ($1=="chr2L" ||... (5 Replies)
Discussion started by: @man
5 Replies

5. Shell Programming and Scripting

Help in understanding awk expression

Hi, Could somebody help me in understanding the following awk expression: awk -v n="POINT" '/%/{print $0 "\n" n ;next}1' < file name Thanks, Arun (6 Replies)
Discussion started by: arun_maffy
6 Replies

6. Shell Programming and Scripting

awk if statement to evaluate string and compare

I have the following simplified code that I am planning on putting into a larger shell script. I have been butchering it to try and make work amongst google searches and reading awk documentation. amixer sset Master toggle | awk '{ if ( /^ Front Left/ { print $7 } == // ) print "MUTED" }'I... (2 Replies)
Discussion started by: jelloir
2 Replies

7. Shell Programming and Scripting

How to evaluate a string of numbers in the same command of AWK

Hi, I am trying to do evaluate one numerical string after substitution. ++++++++++++++++== What I have = "7.04+2.3Xlog(0.72e-6X1.0e6)X1.9596" What I need = evaluate 7.04+2.3*log(0.72e-6*1.0e6)*1.9596 = 5.55941 what I am doing; echo "7.04+2.3Xlog(0.72e-6X1.0e6)X1.9596" | awk... (2 Replies)
Discussion started by: vivek_shm74
2 Replies

8. UNIX for Dummies Questions & Answers

Awk inside Awk expression

Hi, It can be used awk inside other Awk?. I need to get another text processing while other text process. Thank you. (2 Replies)
Discussion started by: pepeli30
2 Replies

9. Shell Programming and Scripting

Regular expression in AWK

Hello world, I was wondering if there is a nicer way to write the following code (in AWK): awk ' FNR==NR&&$1~/^m$/{tok1=1} FNR==NR&&$1~/^m10$/{tok1=1} ' my_file In fact, it looks for m2, m4, m6, m8 and m10 and then return a positive flag. The problem is how to define 10 thanks... (3 Replies)
Discussion started by: jolecanard
3 Replies

10. Shell Programming and Scripting

Check for more than one expression using AWK

I have a txt file like below: testin.txt AB BC CD DE I have the following awk script BEGIN {flag1="N"} /(AB)|(BC)|(CD)|(DE)/ {flag1="Y"} END {print flag1} >awk -f testin.awk testin.txt Returns Y (8 Replies)
Discussion started by: visakhcr
8 Replies
Login or Register to Ask a Question