get value back from awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting get value back from awk script
# 1  
Old 08-18-2008
Bug get value back from awk script

I want to receive a value back into shell script from awk code block.

for example - I want to use the substring value from the awk script inside the shell code's scope.

do
dir=`dirname $file`;
echo | awk '{print substr("'"${dir}"'",'$pathlength')}';
done

can someone guide me how to do that?
any pointers appreciated.
thanks,
Iyer
# 2  
Old 08-18-2008
well, i dont know if it is what u want :
Code:
echo `echo | awk '{print substr("'"$dir"'","'"$pathlength"'")}'`

or:
Code:
var=`echo | awk '{print substr("'"$dir"'","'"$pathlength"'")}'`

# 3  
Old 08-18-2008
You already know how to use backticks. Just put the awk commands in backticks as well.

For bonus points, assuming you don't need the output from dirname other than to pass to awk, maybe something like

Code:
dir=`dirname "$file" | awk -v pathlength=$pathlength '{ print substr($0, pathlength) }'

It's not clear where you are expecting $pathlength to come from, but let's assume you can handle that.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to run a script in back ground within a script

Hi friends, i have two scripts(call it bg1.ksh and bg2.ksh) which needs to be run parallely on background from a script(call it test1.ksh).then i have to wait till these two back ground job gets finished. and once it is completed , then i have to trigger one more script(call it... (4 Replies)
Discussion started by: neelmani
4 Replies

2. Shell Programming and Scripting

Use AWK to move matched line back one?

Can somebody help me with this? I'm sure it's a no-brainer if you know awk... but I don't. Input: Blah Blah Me love you long time Blah Blah awk magic with 'long time' ==> Output: Blah Blah Me love you long time (0 Replies)
Discussion started by: Ryan.
0 Replies

3. Shell Programming and Scripting

Doing a tail in a script and then return back and continue script

Hello all, I am trying to do a tail in a script. But when I quit the tail my script quits also. This is not what I want. I am struggling to get this done. #!/bin/bash askFile() { echo -n "Enter file: " read FILE } doTail() { tail -F "${1}" } askFile doTail... (4 Replies)
Discussion started by: markdark
4 Replies

4. Shell Programming and Scripting

Go back in AWK

Hello! I need to come back one line in awk when i detect a regular expression, i'm working with this: /<POLITIC>/,/<\/POLITIC>/ when i found the line that matches with <\/POLITIC> i need to come back one line, the opposite of getline that takes a new line and continue executing the... (4 Replies)
Discussion started by: claw82
4 Replies

5. Shell Programming and Scripting

Bash script to back up with rsync

I'm trying to write a script to back up with rsync, the script I am posting below: nomServer="shiva horus isis" dirshiva="/etc /faturamento" shivaListExc="/usr/local/bin/shivaListExclRsync" dumpDir="$dumpFile/Shiva" dateBkp=`date +%A` for nServer in ${nomServer} do ... (3 Replies)
Discussion started by: ajmoreti
3 Replies

6. Shell Programming and Scripting

Run script in back ground

I have a script "a" running in background. From script "a" i will kick off script "b" which will also be in background. Is this possible. And actually what i want is, In script "b" when i do ps -ef, script "a" should not be seen. Current "a" script ---- --- ---- nohup b exit current... (1 Reply)
Discussion started by: vasuarjula
1 Replies

7. IP Networking

Back-to-Back Connection using HBAs

Hi every body, Is it possible to connect two servers Back-to-Back (Point-to-Point) using HBA adapters & using Fiber. Note it is direct connection & there is no switches between the servers. I'm concern about using HBA adapters, it is possible or not. Thanks in advance. :) (3 Replies)
Discussion started by: aldowsary
3 Replies

8. Shell Programming and Scripting

how to write shell script to take back up

Helo, I want to write shell script which takes back of all binaries (exe files). and when i uninstall the upgraded system which automatically restore the old binary which we have take as back up. can u tell me how to write such shell scripts. Regards, Amit (5 Replies)
Discussion started by: amitpansuria
5 Replies

9. AIX

back to back printing in UNIX

Hi , Can you suggest me how to back to back printing in UNIX? Is there any way? Kindly advise. Regards Vijaya Amirtha Raj (3 Replies)
Discussion started by: amirthraj_12
3 Replies

10. Shell Programming and Scripting

Is it possible to pass variable from awk to shell back

I am passing a varaible to from Shell to awk then I am doing some maniplation for that variable inside awk. I want that maniplated variable value back to shell , Is this possible .Please let me know. (12 Replies)
Discussion started by: unishiva
12 Replies
Login or Register to Ask a Question