Awk issue using int function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk issue using int function
# 1  
Old 06-28-2010
Awk issue using int function

Hi,

I am having issue with awk command . This command is running in the command prompt but inside a shell script.

Code:
awk -F'| ' 'int($1)==$1 && int($3) ==$3' int_check.txt

Code:
$cat int_check.txt
123|abc|123x
234|def|345

When i run it inside a shell script i am getting the error
Code:
"bailing out near line no 1"

Can anyone help on this.??

Last edited by vgersh99; 06-28-2010 at 11:17 AM.. Reason: code tags, please!
# 2  
Old 06-28-2010
Hi

Try using 'nawk' in place of 'awk'.

Guru.
# 3  
Old 06-28-2010
Code:
# awk -F'| ' 'int($1)==$1 &&int($3)==$3' int_check.txt
awk: illegal primary in regular expression |  at
 input record number 1, file int_check.txt
 source line number 1
# awk -F'|' 'int($1)==$1 &&int($3)==$3' int_check.txt
234|def|345

Remove the extra space from FS
# 4  
Old 06-28-2010
@guruprasad

When i try with nawk i m getting this error:
nawk: syntax error at source line 1
Code:
 context is
         >>> ${ <<<
nawk: bailing out at source line 1

Let me give extra info here.. probably it will help u to help me..

In this command
Code:
awk -F'| ' 'int($1)==$1 && int($3) ==$3' int_check.txt

the value "int($1)==$1 && int($3) ==$3" is obtained from a variable .. i am using that varaible here in the command

Something like this..
Code:
awk -F'| ' '$command' int_check.txt



---------- Post updated at 08:38 AM ---------- Previous update was at 08:14 AM ----------

@danmero

Still i am getting the same error...

Last edited by Franklin52; 06-28-2010 at 02:31 PM.. Reason: Please use code tags
# 5  
Old 06-28-2010
sintasix

try this
Code:
awk -F'| ' '{int($1)==$1 && int($3) ==$3}' int_check.txt

other example is :
Code:
awk -F":" '{ print $1 $3 }' /etc/passwd

and other


Code:
{
    if ( $5 ~ /root/ ) {
        print $3
    }
}


Last edited by Franklin52; 06-28-2010 at 02:31 PM.. Reason: Please use code tags
# 6  
Old 06-28-2010
@ jecaestevez

Hey .. I have tried the command :
Code:
 awk -F'|' '{int($1)==$1 && int($3)==$3}' int_check

I am getting teh following error
Code:
awk: syntax error near line 1
awk: illegal statement near line 1

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. Shell Programming and Scripting

Usage of Int with NR in awk

Hello Everyone, I am new to awk and trying my hand with the diff codes and came across the below code today. It would be great if any of the Guru's help me to understand. awk '{filename = "sample_file" int((NR-1)/34) ".DAT"; print >> filename}' sample_file.DAT 34 is the no of lines each... (7 Replies)
Discussion started by: saratha14
7 Replies

3. Programming

Small query regarding function "char * strerror(int errnum)"

As this function returns the address of the string corressponding to the errno value provided to it. Can someone please let me know where, in the memory, it could be (on freeBSD). The MAN page tells under the BUG section that "For unknown error numbers, the strerror() function will return its... (5 Replies)
Discussion started by: Praveen_218
5 Replies

4. Programming

Function main returning int?

H friends, As we know, a function returns a value and that value is saved somwhere. like int Sum( int x, int y ) { return x + y; } Total = Sum( 10, 20 ); The value 30 is saved in variable Total. Now the question is, what int value does the function main return, and where is it... (5 Replies)
Discussion started by: gabam
5 Replies

5. Shell Programming and Scripting

Advanced AWK Regexp substring to int & Replace

Hi! I have a difficult problem, to step up a unknown version number in a text file, and save the file. It would be great to run script.sh and the version gets increased. Example the content of the textfile.txt hello version = x bye This include three steps 1. First find the char after... (2 Replies)
Discussion started by: Beachboy72
2 Replies

6. Programming

Handle int listen(int sockfd, int backlog) in TCP

Hi, from the manual listen(2): listen for connections on socket - Linux man page It has a parameter called backlog and it limits the maximum length of queue of pending list. If I set backlog to 128, is it means no more than 128 packets can be handled by server? If I have three... (3 Replies)
Discussion started by: sehang
3 Replies

7. Shell Programming and Scripting

Perl int function solved

Hello, I have the below perl function int to return the integer value from the expression but it is not. I am not sure if something misses out here. Any help on this? Thanks in advance. # Code sample Start my $size = int (`1134 sample_text_here`); print "$size \n"; # Code end ----------... (0 Replies)
Discussion started by: nmattam
0 Replies

8. Shell Programming and Scripting

problem in awk int() function

awk -vwgt=$vWeight -vfac=$vFactor ' BEGIN { printf("wgt:" wgt "\n"); printf("factor:" fac "\n"); total = sprintf("%.0f", wgt * fac); total2 = sprintf("%.0f", int(wgt * fac)); printf("total:" total "\n"); printf("total2:" total2 "\n"); } ' if vWeight=326.4 vFactor=100 the result... (2 Replies)
Discussion started by: qa.bingo
2 Replies

9. UNIX for Dummies Questions & Answers

int open(const char *pathname, int flags, mode_t mode) doubt...

hello everybody! I want to create a file with permissions for read, write, and execute to everybody using C, so I write this code: #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(){ int fileDescriptor; fileDescriptor =... (2 Replies)
Discussion started by: csnmgeek
2 Replies

10. Programming

difference between int ** func() and int *& func()

What is the difference between int** func() and int*& func(). Can you please explain it with suitable example. Thanks, Devesh. (1 Reply)
Discussion started by: devesh
1 Replies
Login or Register to Ask a Question