awk - user function?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - user function?
# 8  
Old 10-04-2013
Originally Posted by edstevens
Closer yet. Now how do I get my break line ("==================" back in?
I think you'd need to run it in a subshell:
srvctl config database | awk -F\" '{print $1}' | xargs -I%SUB% sh -c 'srvctl config database -d %SUB% -a; echo ============;'

(or just write a 2-line script for xargs to call instead) but if you're having an issue with the environment not being inherited then you're going to have the same problem as with the other suggested solutions.

EDIT: Although, if inheriting the environment is actually the problem then executing your original /tmp/x$$.sh shouldn't work either.
# 9  
Old 10-04-2013
pamu's suggestion will work if you put the system commands (except the $1) in double quotes. Run Don Cragun's proposal with sh -x and post the resulting output.
# 10  
Old 10-04-2013
Originally Posted by Don Cragun
So run your original script and show us the contents of /tmp/x$$.sh when it is working.

What operating system are you using. (I.e., what is the output from the command uname -a).
Sorry, I should have stated the OS version up front.
Oracle Linux 5.6 x86-64:
oracle:$ uname -a
Linux vbxxxxx.vbdomain 2.6.18- #1 SMP Thu Jan 20 23:52:48 EST 2011 x86_64 x86_64 x86_64 GNU/Linux

The intermediate file looks like this:

oracle:$ ls -ltr /tmp/x*.sh
-rwxrwxrwx 1 oracle oinstall 187 Oct  4 14:43 /tmp/

2013-10-04 14:44:45
oracle:$ cat /tmp/
srvctl config database -d zzzzzzvb -a
echo ==================================================
srvctl config database -d bbbbbbvb -a
echo ==================================================

# 11  
Old 10-04-2013
What's the output from running Don's suggestion with sh -x?
This User Gave Thanks to CarloM For This Post:
# 12  
Old 10-04-2013
Originally Posted by Don Cragun
You're making this way to hard. If your script above works, the following should work just as well without using the temp file:
srvctl config database |
awk -F\" '{print "srvctl config database -d " $1 " -a" \
         RS "echo =================================================="}' |

Following on the rest of the suggestions and revisiting this solution, the addition of the '-x' switch on the 'sh' command was the key. Also had to redirect errout to the bit bucket, else the commands themselves ('srvctl' and 'echo')were also included in the ouput. Final solution is
srvctl config database | \
awk -F\" '{print "srvctl config database -d " $1 " -a" \
        RS "echo =================================================="}' | \
      sh -x 2>/dev/null

I have a couple of other scripts I can go back and retrofit to include this technique as well. Plus the increase in my own understanding.

Thanks to everyone for participating.
# 13  
Old 10-04-2013
All -x does is turn on command trace. It shouldn't make any difference to the execution.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Call user defined function from awk

My requirement is to call function ("fun1") from awk, and print its returned value along with $0. fun1() { t=$1 printf "%02d\n", $t % 60; } echo "Hi There 23" | awk '{print $0; system(fun1 $3)}' Any suggestions what to be modified in above code to achieve requirement.. (5 Replies)
Discussion started by: JSKOBS
5 Replies

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

3. Shell Programming and Scripting

Function to silence rm -rf option for my user

Hi Gurus, I am trying to silence or supress rm -rf option for a particular user(venkat). for that am going to write a function in a script like below #!/bin/bash RM_FUNCTION () { if then case ${1} in -r) ... (9 Replies)
Discussion started by: venky.b5
9 Replies

4. Shell Programming and Scripting

Call function as different user within the script

Hello For HP-UX, ksh shell, is it possible to define functions and call them by another user ? For example <function_name> ( ) { command1 command2 } su - <user> -c <function_name> Or the only option is defining the user in the function itself as follows - <function_name> ( )... (2 Replies)
Discussion started by: atanubanerji
2 Replies

5. UNIX for Dummies Questions & Answers

Problem syntax with user-defined function

Hi ! I got a script from Arabic to Roman numeral conversion - .comp.lang.awk, that I would like to modify to apply it on my input file. input ("|"-delimited fields): AAAAAA|1, 10, 13, 14, 25, 60 wanted output: AAAAAA|I, X, XIII, XIV, XXV, LX script.awk: #!/usr/bin/gawk -f ... (11 Replies)
Discussion started by: lucasvs
11 Replies

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

7. Shell Programming and Scripting

Call Function in .pm as another user

Hello, I need to call a function which reside in some package moudle (.pm) as another user by using su -. Are anyone know how can I do it? Thanks (1 Reply)
Discussion started by: Alalush
1 Replies

8. Shell Programming and Scripting

Return an array of strings from user defined function in awk

Hello Friends, Is it possible to return an array from a user defined function in awk ? example: gawk ' BEGIN{} { catch_line = my_function(i) print catch_line print catch_line print catch_line } function my_function(i) { print "echo" line= "awk" line= "gawk"... (2 Replies)
Discussion started by: user_prady
2 Replies

9. Shell Programming and Scripting

need help with User Defined Function

Dear Friends, I need a help regarding User defined function in shell script. My problem is as follows: my_funcI(){ grep 'mystring' I.dat } my_funcQ(){ grep 'mystring' Q.dat } myfuncI myfuncQ But As both the function has same function only the... (11 Replies)
Discussion started by: user_prady
11 Replies

10. Shell Programming and Scripting

Nawk user-defined function

HELP!!!! I am in an on-line shell programming class and have a question. Here is the data: Mike Harrington:(510) 548-1278:250:100:175 Christian Dobbins:(408) 538-2358:155:90:201 Susan Dalsass:(206) 654-6279:250:60:50 (There are 12 contribuors total) This database contains names, phone... (1 Reply)
Discussion started by: NewbieGirl
1 Replies
Login or Register to Ask a Question