Sponsored Content
Full Discussion: awk Print get error
Top Forums Shell Programming and Scripting awk Print get error Post 302533013 by Corona688 on Wednesday 22nd of June 2011 03:23:04 PM
Old 06-22-2011
That's a useless use of backticks. Why do "var=`cat stuff` ; echo $var" when just "cat stuff" achieves the same thing?

It's valid in my awk. Depending on your system, 'awk' may actually be an ancient feature-deprived version, try nawk.

I'm not sure it's actually doing what you want either, though. That $$ may be turning into a number, the shell's PID.

There's an easier and safer way to get variables into awk/nawk than fooling with single/double quotes:

Code:
echo asdf | awk -v var="qwerty" '{ print $1, var }'

---------- Post updated at 01:23 PM ---------- Previous update was at 01:15 PM ----------

Or even get the var in awk itself:
Code:
awk 'BEGIN { getline var <"abc" } { print $0, var }'


Last edited by Corona688; 06-22-2011 at 04:26 PM.. Reason: fix typos, sorry
This User Gave Thanks to Corona688 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do I get awk to print a " in it's print part?

The line is simple, use " '{ print $1"]"$2"\"$3THE " NEEDS TO GO HERE$4 }' I've tried \", "\, ^" and '"" but none of it works. What am I missing? Putting in the [ between $1 and $2 works fine, I just need to do the same with a ". Thanks. (2 Replies)
Discussion started by: LordJezo
2 Replies

2. Shell Programming and Scripting

i want to print following using awk

Hi all I have taken input $fname=filename.345.txt Now i want to awk with using delimiter as '.' and print last word. i.e in this case it is "txt". I have tired like this echo $filename | awk -F"." '{print $END}' but it is not working. Can any one help me Thank U Naree (2 Replies)
Discussion started by: naree
2 Replies

3. Shell Programming and Scripting

awk - print

Hi all, I have script below: #!/bin/sh $name=blah awk -F: -v user="$name" '$1 == user{print $1 ":" $2 ":" $3 ":" $4}' /etc/shadow > /tmp/shadow.tmp based on above, it will only print one line which is "blah" username details. What do i need to do to print all contents of shadow... (6 Replies)
Discussion started by: c00kie88
6 Replies

4. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

5. Shell Programming and Scripting

Print using awk

Hi.. I have two files. contents of the files are as below. header1.dat ------------- This is a header record. header2.dat ------------- This is a header record. Date:2011-01-05 I am executing the below scripts. HEADER1=`cat header1.dat` HEADER2=`cat header2.dat` awk 'BEGIN... (2 Replies)
Discussion started by: 46019
2 Replies

6. Shell Programming and Scripting

AWK print AWK command

awk '{print "awk '{sub(/pdb_00/,"pdb_"$0"_00"); print}' pdb_"$0"_00.namd > tempo"; print "mv tempo pdb_"$0"_00.namd"}' datA2.dat > copy_script2.bash This works when trying to print 'sed etc. etc' but if I switch to using AWK to print a set of AWK commands it doesn't work... e.g. this... (3 Replies)
Discussion started by: chrisjorg
3 Replies

7. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

8. Shell Programming and Scripting

Awk: Print count for column in a file using awk

Hi, I have the following input in a file & need output as mentioned below(need counter of every occurance of field which is to be increased by 1). Input: 919143110065 919143110065 919143110052 918648846132 919143110012 918648873782 919143110152 919143110152 919143110152... (2 Replies)
Discussion started by: siramitsharma
2 Replies

9. Shell Programming and Scripting

Awk: Print Error While Redirecting output in multiple Files

Hi, I have a following code in which I am unable to redirect to multiple files. Can anybody please help with some corrections awk -F, '{ if ( substr($1,26,2)=="02" && substr($1,184,14)=="MTSCC_VALFIRST") { array1++ array2++ array3++ } else if (substr($1,26,2)=="03" &&... (4 Replies)
Discussion started by: siramitsharma
4 Replies

10. UNIX for Beginners Questions & Answers

Print Error in Console and both Error & Output in Log file - UNIX

I am writing a shell script with 2 run time arguments. During the execution if i got any error, then it needs to redirected to a error file and in console. Also both error and output to be redirected to a log file. But i am facing the below error. #! /bin/sh errExit () { errMsg=`cat... (1 Reply)
Discussion started by: sarathy_a35
1 Replies
IGAWK(1)							 Utility Commands							  IGAWK(1)

NAME
igawk - gawk with include files SYNOPSIS
igawk [ all gawk options ] -f program-file [ -- ] file ... igawk [ all gawk options ] [ -- ] program-text file ... DESCRIPTION
Igawk is a simple shell script that adds the ability to have ``include files'' to gawk(1). AWK programs for igawk are the same as for gawk, except that, in addition, you may have lines like @include getopt.awk in your program to include the file getopt.awk from either the current directory or one of the other directories in the search path. OPTIONS
See gawk(1) for a full description of the AWK language and the options that gawk supports. EXAMPLES
cat << EOF > test.awk @include getopt.awk BEGIN { while (getopt(ARGC, ARGV, "am:q") != -1) ... } EOF igawk -f test.awk SEE ALSO
gawk(1) Effective AWK Programming, Edition 1.0, published by the Free Software Foundation, 1995. AUTHOR
Arnold Robbins (arnold@skeeve.com). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgawk | +--------------------+-----------------+ |Interface Stability | Volatile | +--------------------+-----------------+ NOTES
Source for gawk is available on http://opensolaris.org. Free Software Foundation Nov 3 1999 IGAWK(1)
All times are GMT -4. The time now is 12:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy