Sponsored Content
Top Forums Shell Programming and Scripting accessing ksh variables from awk Post 302108297 by trupti wagh on Monday 26th of February 2007 02:46:19 AM
Old 02-26-2007
Bug accessing ksh variables from awk

hi everybody!
i am running this ksh script for replacing a set of strings by another set of new ones. i am getting both these from a file.
also, the strings that i want to replace, are sub-strings(can occur more than once in each chunk) in a big chunk of data that i have bulk-copied(bcp utility) from a database. i can do it successfully, but it so happens that some of the set of strings that need to be replaced are mutually sub-strings of eachother. like for example, the file containing the sets of strings includes the following::

abc abc:x
abcd abcl.x
...etc.

now while replacement with the first set of strings the instances of the second string get altered...
abc:xd

i am trying to use gawk FIELDWIDTHS for this with the following code snippet:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cp ${ORIGFILE} ${TMPFILE}

sed "s/\*/\\\*/g" ${SYMLISTFILE} > ${NEWSYMLIST}
while read OLDSYM NEWSYM FLDLEN
do
gawk 'BEGIN{ FIELDWIDTHS = ${FLDLEN} } END{ s/${OLDSYM}/${NEWSYM}/g }'
# sed "s/${OLDSYM}/${NEWSYM}/g" ${TMPFILE} > ${INFILE}
cp ${INFILE} ${TMPFILE}
done < ${NEWSYMLIST}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
while running the script now i get the following error for the ${FLDLEN}::
gawk: cmd. line:1: BEGIN{ FIELDWIDTHS = ${FLDLEN} } END{ s/${OLDSYM}/${NEWSYM}/g }
gawk: cmd. line:1: ^ parse error

please can anyone help me writing a viable code that can access the FLDLEN from the ksh script to the gawk script?
is gawk freely available to install... and is its installation the solution?

Thanking you in advance,
Tru.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing variables to awk from ksh script

I'm trying to write a ksh script that uses awk, but I want to pass variables to awk. For example (not working): if ];then searchstr=$1 lsof -i | awk '{if($9~/SEARCHSTR/) print $2} SEARCHSTR=$searchstr' else echo "usage: $0 <search string>" fi I tried several options. Is it... (3 Replies)
Discussion started by: rein
3 Replies

2. Shell Programming and Scripting

Accessing Variables from .conf file

I can't figure out how to access variables that are stored in a separate file. Can someone let me in on the secret? Please, and thank you. -Kevin (7 Replies)
Discussion started by: wayne1411
7 Replies

3. Programming

accessing unix variables in oracle

Hi, consider the following script. ip='***.***.**.**' user='****' pw='******' ftpresults=`ftp -nv $ip<<EOF user $user $pw cd /home/oracle/practice size $1 bye EOF` fname=$1 echo $ftpresults sqlplus -s tms/tms@dev45 <<"EOF" insert into remote_file_sizes (file_name,file_size)... (1 Reply)
Discussion started by: ravi raj kumar
1 Replies

4. Shell Programming and Scripting

Accessing Shell Variables in awk or sed

Hello, I wonder if it is possible to pass and use variables from shell environment into sed or awk. I am trying to achieve something similar to the following using sed or awk: var=some_regular_expression grep "$var" filename # Will extract lines from filename The following code,... (3 Replies)
Discussion started by: nasersh
3 Replies

5. Shell Programming and Scripting

Problem in accessing variables outside shell

Hi, I have a shell script wherein i am doing some file operations and storing the data in some variables. I am exporting these variables as i need to use them outside shell. Then within the shell i am launching GDB session hoping that i will be able to access the exported variables in the GDB... (2 Replies)
Discussion started by: jsantosh
2 Replies

6. Shell Programming and Scripting

Accessing the Value of a parameter in KSH

Hi I am new to this forum. Please forgive me, If I am wrong anywhere. I am trying to understand the below code. Can anyone help in understanding what is ${#ST} here. Is that the value of the first parameter??:confused:...what is exit 1 mean. Any clarification is greatly appreciated. export... (3 Replies)
Discussion started by: suaven
3 Replies

7. Shell Programming and Scripting

Accessing variables outside the function

I have the below code to find yesterdays date, In this I want to make MONTH, DAY and YEAR as global variableand use it outside the {}, but I am unable to do so , please assist: #!/usr/bin/ksh date '+%m %d %Y' | { read MONTH DAY YEAR DAY=`expr "$DAY" - $1` case "$DAY" in 0) ... (1 Reply)
Discussion started by: mohsin.quazi
1 Replies

8. Shell Programming and Scripting

awk splits file in to multiple - how to get filenames in variables withing ksh?

Hi all, I'm using awk in a .ksh script to split one file by line prefix into different files (up to 4). The files are named after the prefix in the line, and a sequence no. Is there any way to get the filenames in to variables too? I need _ftpfile1, _ftpfile2, _ftpfile3 and _ftpfile4 which are... (2 Replies)
Discussion started by: spidermike
2 Replies

9. Shell Programming and Scripting

awk issue expanding variables in ksh script

Hi Guys, I have an issue with awk and variables. I have trawled the internet and forums but can't seem to get the exactt syntax I need. I have tried using awk -v and all sorts of variations but I have hit a brick wall. I have spent a full day on this and am just going round in circles. ... (3 Replies)
Discussion started by: gazza-o
3 Replies

10. 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
suspend(1)							   User Commands							suspend(1)

NAME
suspend - shell built-in function to halt the current shell SYNOPSIS
sh suspend csh suspend ksh suspend DESCRIPTION
sh Stops the execution of the current shell (but not if it is the login shell). csh Stop the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su. ksh Stops the execution of the current shell (but not if it is the login shell). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), kill(1), ksh(1), sh(1), su(1M), attributes(5) SunOS 5.10 15 Apr 1994 suspend(1)
All times are GMT -4. The time now is 03:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy