Sponsored Content
Full Discussion: Variables in an awk command
Top Forums Shell Programming and Scripting Variables in an awk command Post 302843011 by magicjoe on Sunday 11th of August 2013 03:21:20 PM
Old 08-11-2013
Thank you Yoda, you truly are a Jedi Master! the escapes seem to help some, but I am still "so close, yet so far away". I am posting my code here, I have documented where the issue is, and it is set up for debugging as it is. I can echo the command and the results are what I want, but it still is not quite perfect.
Code:
#!/bin/bash
#
#
#
#
#
#Adds username to .group file with prompts
#
########################################

# Lets the user know that they will have a backup of the .group file

clear

echo "==================================================="
echo "Welcome to the Report Access Tool.  As a precaution"
echo "a copy of the customer .group file will be copied  "
echo "to your home directory before the command completes"
echo "PRESS ENTER TO CONTINUE .......................  "
echo "==================================================="

read


clear

# prompt for username

echo "================================================="
echo "Enter the username that needs to access reports?"
echo "================================================="

read EmonUser

clear

# get customer

echo "================================================="
echo "  Which customer's reports are they accessing?"
echo "================================================="

read customer




# here is where we are sending a backup of the file, before doing our work, just in case
# commented out for testing
cp $customer.group ~/$customer.group.bak


# initiate a loop sequence that will allow the user to be added to multiple groups

while [ "$loop" != "n" ]
do

clear

echo "================================================="
echo "  Which report does this user need access to?"
echo "================================================="

# this line uses awk to display the group names of all lines in the file
awk -F':' '{ print NR " " $1 }' $customer.group


read reportline




# THIS IS THE COMMAND THAT HAS THE ISSUE. SET AS VARIABLE ONLY FOR DEBUGGING
keycommand="awk 'NR=="${reportline}"{\$NF=\$NF\" "${EmonUser}"\"}1' $customer.group"

echo $keycommand


# uncomment this read line to debug the above  command with echo
read
# ABOVE THIS LINE IS ONLY USED AT THIS TIME FOR DEBUGGING the results of echo $keycommand at this point are what needs to run
# once that piece works, I will append the > AddToGroup.tmp && mv AddToGroup.tmp $customer.group


clear

echo "====================================================="
echo "Do you want to add this user to another report? (Y/N)"
echo "====================================================="

read doitagain

# nested loop will repeat first loop until they answer no to adding to another group.


while [ "doitagain" != "n" ]
do

# case statment will exit this loop if they want to add to another report
# or will exit this loop, and then close the first loop, ending the script for no
# if the input is not Y or N, second loop starts again, forcing a valid answer
case $doitagain
in
[nN]) doitagain="n" ; loop="n" ; clear; break;;
[yY]) doitagain="y" ; break;;
   *) clear; echo "====================================================="; echo "Invalid action.  Add to another report?  Y or N"; echo "====================================================="; read doitagain;;
esac

done

# cleans up the temp file created
#rm AddToGroup.tmp

done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk and Variables

Hi, I have some files in metrica (assume a pre-defined format) which i need to process and have some values in a .csv file. The script that does this, part of which is: procMetricaOMData() { host=$1 fileIN=$2 fileOUT=$3 $CATCMD $fileIN | \ awk -f... (4 Replies)
Discussion started by: deepak4you
4 Replies

2. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

3. UNIX for Dummies Questions & Answers

Using variables in AWK

Hi, I'm pretty new to AWK and was wondering if someone could let me know how to execute varibles within an AWK statement. An example is below: NO=6 end=25 awk = 'NR == $NO, NR == $end' file1 > file2 I'm currently attempting to use this within a script but awk seems to read $NO and... (2 Replies)
Discussion started by: chris01010
2 Replies

4. Shell Programming and Scripting

Using AWK variables.

Hi all, I am new to the forum and Shell Script programming. The problem is: I need to do a script to search all system processes and show me hierarchical way the number of bytes occupied by each of the regions of the memory map of each process. Today I got to show me the number of regions in... (3 Replies)
Discussion started by: cougar_rea
3 Replies

5. 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

6. UNIX Desktop Questions & Answers

Variables within awk

Hi, I'm having trouble getting awk to read a variable with spaces in it. Input: vendorName="Bob's Steakhouse" awk -F":" '$2 ~ /'$vendorName'/ {print $1}' Purchases.dat Error: awk: $2 ~ /Bob's awk: ^ unterminated regexp The awk command isn't recognizing the entire string. It... (2 Replies)
Discussion started by: Cablephish
2 Replies

7. UNIX for Dummies Questions & Answers

Passing Shell Variables to an awk command

Hello, I have two files File1 & File2. File1 76 135 136 200 250 345 .... File2 1 24 1 35 1 36 1 72 .... I want to get all the values form File2 corresponding to the range in File 1 and feed it to a program. Is the code below right? Can I pass shell variables to awk in this... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

8. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies

9. Shell Programming and Scripting

awk - Why can't value of awk variables be passed to external functions ?

I wrote a very simple script to understand how to call user-defined functions from within awk after reading this post. function my_func_local { echo "In func $1" } export -f my_func_local echo $1 | awk -F"/" '{for (k=1;k<=NF;k++) { if ($k == "a" ) { system("my_local_func $k") } else{... (19 Replies)
Discussion started by: sreyan32
19 Replies

10. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. --font=desc Set the font description. Default is Monospace 12. --rtl Do rtl layout. --paper ps Choose paper size. Known paper sizes are legal, letter, a4. Default is A4. --bottom-margin=bm Set bottom margin in postscript points (1/72 inch). Default is 36. --top-margin=tm Set top margin. Default is 36. --left-margin=lm Set left margin. Default is 36. --right-margin=rm Set right margin. Default is 36. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --encoding=ENCODING Assume the documentation encoding is ENCODING. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 04:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy