Sponsored Content
Top Forums Shell Programming and Scripting Using variable in awk command Post 302786187 by hergp on Wednesday 27th of March 2013 04:33:52 AM
Old 03-27-2013
After reformatting your script

Code:
ITERATOR=0
COUNT=`cat test.txt`
echo "$COUNT"

while [ $ITERATOR -lt $COUNT ]
do
    echo $ITERATOR
    echo "$COUNT"
    awk 'NR=="$ITERATOR" {print;exit}' EMAIL_REPORT.CSV >temp_mail.txt
    TO=`cat temp_mail.txt`
    ITERATOR=`expr $ITERATOR + 1`
done

you can see, that your awk script is enclosed in single quotes. They prevent variable expansion, so awk sees the literal text $ITERATOR. Also, since $ITERATOR is supposed to be a number, you don't need the double quotes.

Code:
awk 'NR=='$ITERATOR' {print;exit}' EMAIL_REPORT.CSV >temp_mail.txt

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing variable values to awk command

Hi, I have a situation where I have to specify a different value to an awk command, I beleive i have the gist of this done, however I am not able to get this correct. Here is what I have so far echo $id 065859555 This value occurs in a "pipe" delimited file in postition 8. Hence I would... (1 Reply)
Discussion started by: jerardfjay
1 Replies

2. Shell Programming and Scripting

Execution of awk command in a variable

Hi All, I have a awk command that is stored in a variable. the value of the variable cmd is: (mean output of echo $cmd is: ) awk -F";" '{print $1}' Now I want to execute this command. How can I do that???? Quick Reply will be appreciated. Regards, Amit (2 Replies)
Discussion started by: patelamit009
2 Replies

3. Shell Programming and Scripting

How to use same variable value inside as well as outside of the awk command?

Hi Jim, The following script is in working state. But i m having one more problem with awk cmd. Could you tell me how to use any variable inside awk or how to take any variable value outside awk. My problem is i want to maintain one property file in which i am declaring variable value into that... (12 Replies)
Discussion started by: Ganesh Khandare
12 Replies

4. Shell Programming and Scripting

Problem with Variable and AWK command

Okay, so I am trying to use a count variable to reference the column of output sent from an echo statement. So I am trying to do this #!/bin/bash CURRENT=$PWD VAR=3 CHANGE=`echo $CURRENT | awk -F "/" '{ print \$$VAR }'` This instead of giving me the third instance after the "/" gives... (4 Replies)
Discussion started by: mkjp2011
4 Replies

5. Shell Programming and Scripting

use shell variable in awk command

Trying to do something like this ls -lrt | awk '$9=="test5"' -rw-r--r-- 1 lrmq db2iadm1 381 Sep 20 21:56 test5 But now, I need to give a variable in place of test5. For example let's define x as test5 x=test5 ls -lrt | awk '$9=="$x"' This doesn't seem to be working. It doesn't take the... (4 Replies)
Discussion started by: blazer789
4 Replies

6. Shell Programming and Scripting

Variable as input to awk command

Hi Gurus, I need a suggestion, please help. I have a input file as below : abc.txt : * xxxx: 00000 xxxxx: 00000 xxxx: RANDOM xxx: RANDOM **************************xxxxxxx*** * abc ****************************** abc: abc: ... (3 Replies)
Discussion started by: arunshankar.c
3 Replies

7. Shell Programming and Scripting

Variable in AWK command help

here is what i have so far delim=`cat $HOME/tmp/interchange_hold | head -1 | cut -b4` cat $HOME/tmp/rawfile_hold | ( while read line se_check=`echo $line | awk -F: -v awkvar="$delim" '{ print $1}'` delim will hold the 4th char of a file. Lets say that char is a * the line im... (2 Replies)
Discussion started by: blesjt02
2 Replies

8. UNIX for Dummies Questions & Answers

Using a variable in the awk command

Hi Guys, Can anyone of you please tell me how to use a variable inside a awk command. For ex - if am printing the third column with respect to a pattern with delimiter ~ awk -F~ '$3=="pattern"' <file name> - This works, Now here I have a set of patterns in a file and I want to put it in... (1 Reply)
Discussion started by: abhisheksunkari
1 Replies

9. Shell Programming and Scripting

Storing awk command in a variable

I'm working on a script in which gives certain details in its output depending on user-specified options. So, what I'd like to do is something like: if then awkcmd='some_awk_command' else awkcmd='some_other_awk_command' fi Then, later in the script, we'd do something like: ... (5 Replies)
Discussion started by: treesloth
5 Replies

10. Shell Programming and Scripting

Variable in awk command

Hello All, I am trying to run a script to extract data from the file. The format of the file is as below: filename: sample.log 12345| ABCD 23456| GKHY 33454| ABCD 98765| TTRRI want to run a command in AWK as show below extract.sh #!/bin/bash echo... (2 Replies)
Discussion started by: chetanojha
2 Replies
unix2dos(1)						      General Commands Manual						       unix2dos(1)

NAME
unix2dos - UNIX to DOS text file format converter SYNOPSYS
unix2dos [options] [-c convmode] [-o file ...] [-n infile outfile ...] Options: [-hkqV] [--help] [--keepdate] [--quiet] [--version] DESCRIPTION
This manual page documents unix2dos, the program that converts text files in UNIX format to DOS format. OPTIONS
The following options are available: -h --help Print online help. -k --keepdate Keep the date stamp of output file same as input file. -q --quiet Quiet mode. Suppress all warning and messages. -V --version Prints version information. -c --convmode convmode Sets conversion mode. Simulates unix2dos under SunOS. -o --oldfile file ... Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used. -n --newfile infile outfile ... New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files. EXAMPLES
Get input from stdin and write output to stdout. unix2dos Convert and replace a.txt. Convert and replace b.txt. unix2dos a.txt b.txt unix2dos -o a.txt b.txt Convert and replace a.txt in ASCII conversion mode. Convert and replace b.txt in ISO conversion mode. unix2dos a.txt -c iso b.txt unix2dos -c ascii a.txt -c iso b.txt Convert and replace a.txt while keeping original date stamp. unix2dos -k a.txt unix2dos -k -o a.txt Convert a.txt and write to e.txt. unix2dos -n a.txt e.txt Convert a.txt and write to e.txt, keep date stamp of e.txt same as a.txt. unix2dos -k -n a.txt e.txt Convert and replace a.txt. Convert b.txt and write to e.txt. unix2dos a.txt -n b.txt e.txt unix2dos -o a.txt -n b.txt e.txt Convert c.txt and write to e.txt. Convert and replace a.txt. Convert and replace b.txt. Convert d.txt and write to f.txt. unix2dos -n c.txt e.txt -o a.txt b.txt -n d.txt f.txt DIAGNOSTICS
BUGS
The program does not work properly under MSDOS in stdio processing mode. If you know why is that so, please tell me. AUTHOR
Benjamin Lin - ( blin@socs.uts.edu.au ) MISCELLANY
Tested environment: Linux 1.2.0 with GNU C 2.5.8 SunOS 4.1.3 with GNU C 2.6.3 MS-DOS 6.20 with Borland C++ 4.02 Suggestions and bug reports are welcome. SEE ALSO
dos2unix(1) 1995.03.31 unix2dos v2.2 unix2dos(1)
All times are GMT -4. The time now is 12:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy