Sponsored Content
Top Forums UNIX for Dummies Questions & Answers What is the difference in this two awk command? Post 302974224 by Scott on Thursday 26th of May 2016 03:35:04 PM
Old 05-26-2016
The first one turns ("casts") the "strings" into numbers.

If the output's the same on both, it's probably because the input is already numerical.

Code:
$ echo a b c | awk '{ print $1, $2, $3 }'
a b c
$ echo a b c | awk '{ print $1+0, $2, $3 }'
0 b c
$ echo a b c | awk '{ print $1+0, $2+0, $3 }'
0 0 c
$ echo a b 27 | awk '{ print $1+0, $2+0, $3 }'
0 0 27
$ echo a b 27 | awk '{ print $1+0, $2+0, $3+0 }'
0 0 27
$ echo a b 27 | awk '{ print $1+0, $2+0, $3+1 }'
0 0 28
$

This User Gave Thanks to Scott For This Post:
 

10 More Discussions You Might Find Interesting

1. AIX

difference between ls -b and ls command

hi anyone please tell me what is the difference between ls -b command and ls command. (1 Reply)
Discussion started by: sathish2win
1 Replies

2. Programming

Difference between cp and mv linux command

Hi, I am facing one problem only with mv command not with cp command. I have a test program #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mount.h> #include <fcntl.h> #include <errno.h> int sync_file(char *file) { FILE *fp=NULL;... (6 Replies)
Discussion started by: dharshini123
6 Replies

3. Shell Programming and Scripting

awk command in script gives error while same awk command at prompt runs fine: Why?

Hello all, Here is what my bash script does: sums number columns, saves the tot in new column, outputs if tot >= threshold val: > cat getnon0file.sh #!/bin/bash this="getnon0file.sh" USAGE=$this" InFile="xyz.38" Min="0.05" # awk '{sum=0; for(n=2; n<=NF; n++){sum+=$n};... (4 Replies)
Discussion started by: catalys
4 Replies

4. UNIX for Dummies Questions & Answers

which command difference

What is the difference between (unix-system “which ) and which commands. For example when I use the (unix-system “which visual_elite) command I get the following result: /home/vhdl/edatools/mentor/visualelite/VisualElite-4.2.1/Linux2.4/bin/visual_elite When I do the same on... (1 Reply)
Discussion started by: mihaelab
1 Replies

5. Shell Programming and Scripting

AWK Script and Commandline difference

Hey there, I just stumbled upon a difference between using awk on the commandline and using it in a shellscript. I have a variable, e.g.: PROG=vim then i want to check if the package with this name is installed: TEMPVAL=$(dpkg -l | awk '{ if ($2 == "$PROG") print $2 }') (Im using... (10 Replies)
Discussion started by: MrSnail
10 Replies

6. UNIX for Dummies Questions & Answers

command difference - find

Hi, What is the difference between these two? find /some_dir -type f -exec chmod 070 {} \; and chmod 070 `find /some_dir -type f` Thanks (5 Replies)
Discussion started by: lamont
5 Replies

7. Shell Programming and Scripting

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies

8. Shell Programming and Scripting

Awk: What is the difference between: X[a,b,c] - X[a][b,c] - X[a][b][c]

I have awk appearing to behave inconsistently. With the same variable it will give the message: fatal: attempt to use array `X' in a scalar context and, if I try to correct that, then: fatal: attempt to use a scalar value as array I'm using a three dimensional array. There seems to be a... (2 Replies)
Discussion started by: Fustbariclation
2 Replies

9. Shell Programming and Scripting

Difference in awk output and while

so, im going over one of my scripts and trying to optimize it. i have a code like this: cksum sjreas.py | awk '{prinnt $1$2}' This does what I need. However, i dont want to call the external command awk. so im doing this: cksum sjreas.py | while OFS=' ' read v1 v2 ; do printf... (4 Replies)
Discussion started by: SkySmart
4 Replies

10. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies
STDBUF(1)						    BSD General Commands Manual 						 STDBUF(1)

NAME
stdbuf -- change standard streams initial buffering SYNOPSIS
stdbuf [-e bufdef] [-i bufdef] [-o bufdef] [command [...]] DESCRIPTION
stdbuf is used to change the initial buffering of standard input, standard output and/or standard error streams for command. It relies on libstdbuf(3) which is loaded and configured by stdbuf through environment variables. The options are as follows: -e bufdef Set initial buffering of the standard error stream for command as defined by bufdef (see BUFFER DEFINITION). -i bufdef Set initial buffering of the standard input stream for command as defined by bufdef (see BUFFER DEFINITION). -o bufdef Set initial buffering of the standard output stream for command as defined by bufdef (see BUFFER DEFINITION). BUFFER DEFINITION
Buffer definition is the same as in libstdbuf(3): "0" unbuffered "L" line buffered "B" fully buffered with the default buffer size size fully buffered with a buffer of size bytes (suffixes 'k', 'M' and 'G' are accepted) EXAMPLES
In the following example, the stdout stream of the awk(1) command will be fully buffered by default because it does not refer to a terminal. stdbuf is used to force it to be line-buffered so vmstat(8)'s output will not stall until the full buffer fills. # vmstat 1 | stdbuf -o L awk '$2 > 1 || $3 > 1' | cat -n SEE ALSO
libstdbuf(3), setvbuf(3) HISTORY
The stdbuf utility first appeared in FreeBSD 8.4. AUTHORS
The original idea of the stdbuf command comes from Padraig Brady who implemented it in the GNU coreutils. Jeremie Le Hen implemented it on FreeBSD. BSD
April 28, 2012 BSD
All times are GMT -4. The time now is 07:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy