kshell variables and awk


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers kshell variables and awk
# 1  
Old 11-27-2006
kshell variables and awk

Hi,

Is it possible to initialise a shell variable and set it to a value from an awk command?

i.e.

#set myvalue = to the first 8 charachters of the line that begins with 0
myvalue = awk '/^0/ {substr($0,1,8)}' myvaluefile

or even declare a variable, then reinitialise it as part of the awk command, such as:

myvalue="TEST"
awk '/^0/ {$myvalue=substr($0,1,8)}' myvaluefile

I'm new to shell scripting so I'm not even sure if this is possible?

Thanks
# 2  
Old 11-27-2006
Try...
Code:
myvalue=$(awk '/^0/ {print substr($0,1,8)}' myvaluefile)

More info: Command Substitution
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

4. Shell Programming and Scripting

Please help with Kshell Script!

I am an AIX noobie, and have a question around an AIX 5.2 script that I need to run. Security Audit requires us to have no World Writable files on our server, but every time we restart the Domino server on AIX it re-flags two files as World Writable. I have a little script that I created that... (5 Replies)
Discussion started by: Nebs
5 Replies

5. Linux

how to insert a title into a window in kshell

hi all, i am using a Ubuntu work station. i have following piece of code that works ok. But i cant figure out a way to insert a string call $Name into the title of the window i am opening. As you can see, i tried two different ways without a success. Can someone please help me out here? :( ... (3 Replies)
Discussion started by: usustarr
3 Replies

6. Shell Programming and Scripting

KShell regular expresion

Hi, I would like to know if the parameter i am passing to a shell script is contain the following charachter : ASM. I belive that i should use regular expresion here. Can one help ? Bellow is the "if statment" i need to fix with the reg exp: if ; then #echo "IT IS AN RDBMS... (4 Replies)
Discussion started by: yoavbe
4 Replies

7. Shell Programming and Scripting

How to see a variable value outside a function in kshell

Hi, I wrote a small shell script which had function C_fun() and script name is same C_fun.ksh Here is the program inside the script #!bin/ksh -x C_fun() { typeset TEXT=${1} } echo Value of TEXT $TEXT When Im running the above script with Parameter "R" as the option .... (6 Replies)
Discussion started by: somu_june
6 Replies

8. Shell Programming and Scripting

Substring operation in kshell

Hi, Please let me know how to perform the substring operation in kshell. If i have line like below 238923893282389034893489458945904589045454903490 i would like to retrieve the position 7 to 19, how to do this in kshell? (1 Reply)
Discussion started by: informsrini
1 Replies

9. Shell Programming and Scripting

running .sh script in kshell

hi i wrote a script in shell script(ChangeFiles.sh), now i need to run the script in korn shell. could anyone explain how to run the same script korn shell. thanks in advance Satya (2 Replies)
Discussion started by: Satyak
2 Replies

10. AIX

Kshell scripts and timing

Hello everyone, I have a script thats acting funky, what I would like to do is report to a file, how long its taking to get to certain area's, in seconds. For example. -- Start timer -- Run unix command 1 -- Run unix command 2 -- Stop timer -- Report Seconds -- etc etc Is there a way... (3 Replies)
Discussion started by: dbridle
3 Replies
Login or Register to Ask a Question