AIX Korn shell sed -s problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AIX Korn shell sed -s problem
# 1  
Old 04-28-2009
AIX Korn shell sed -s problem

In a Korn shell script I have,
cat ../header | sed -e 's/flag1/$cnumb/g' > header.txt
The header is short
{{Company flag1}}
But the result in header.txt is
{{Company $cnumb}}
The value of $cnumb is 120. I am trying to get the value of $cnumb into the header.
I have tried /'$cnumb'/g, /${cnumb}/, they cause other errors.
Can anybody tell me how to change the place holder flag1 with the value of $cnumb?
# 2  
Old 04-28-2009
Code:
sed -e "s/flag1/$cnumb/g" ../header > header.txt

# 3  
Old 04-28-2009
The error returned is
sed: 0602-404 Function s/flag1/ cannot be parsed.
The single quotes work on AIX not the double.
# 4  
Old 04-28-2009
Quote:
Originally Posted by jcarrott
The error returned is
sed: 0602-404 Function s/flag1/ cannot be parsed.
The single quotes work on AIX not the double.
very strange...........
Code:
$ cat jc.txt
{{Company flag1}}
$ cnumb=5
$ sed -e "s/flag1/${cnumb}/g" jc.txt
{{Company 5}}

# 5  
Old 04-28-2009
I don't know if the whole script makes a difference, but here it is.


for FaxFile in `ls *`
do
phone=`cut -d, -f5 $FaxFile`
cnumb=`cut -d, -f7 $FaxFile`
ponum=`cut -d, -f11 $FaxFile`
cname=`sed -n 3p $FaxFile | cut -d, -f2`
sed -e 's/flag1/$cnumb/g' ../header > $FaxFile.txt
# cat ../header | sed 's/flag1/$cnumb/g' > header.txt
# cat header.txt | sed 's/flag2/$ponum/g' > header.txt
# cat header.txt | sed 's/flag3/$cname/g' > header.txt
# cat header.txt | sed 's/flag4/$phone/g' > header.txt
# cp header.txt $FaxFile.txt
# rm header.txt
done

The result is

{{Begin}}
{{Company $cnumb}}
{{Winsecid LAWSON_FAX}}
{{POnumb flag2}}
{{Contact flag3}}
{{Endcovertext}}
{{Fax flag4}}

This should have been a simple substitution.
# 6  
Old 04-28-2009
you're still using SINGLE quotes - use DOUBLE quotes as suggested.
Also debug you script by adding the 'set -x' at the top of file and you'll see your variables expanded.
# 7  
Old 04-28-2009
Thank you for the help, but as I stated in my first reply - the double quotes caused an error.

sed: 0602-404 Function s/flag1/ cannot be parsed.

There is no error with the single quotes. I don't know if the issue is because this is an AIX environment or if has to do with how the system was installed.

Thank you for trying to help. I am working with the set -x at this time.
This User Gave Thanks to jcarrott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help when using Typeset in AIX Korn Shell

Guys, please help! I am currently using an AIX server however whenever I tried to use the typeset -F3, the variable is resulting with a "#". In the given example below, I declared x to be a decimal holding 3 decimal places = 1.455. However whenever I tried to echo the $x, the resulting value... (9 Replies)
Discussion started by: zzavilz
9 Replies

2. Shell Programming and Scripting

Korn shell behaviour in AIX

Hi, Consider the code snippet below: fun() { while read x do echo $x done < somefile_that_does_not_exists } fun echo I am here Korn shell on HPUX prints the message "I am here", while the behaviour is different on AIX korn shell. We do not get the message on AIX. Any... (5 Replies)
Discussion started by: 116@434
5 Replies

3. UNIX for Dummies Questions & Answers

List of 'if -f' options - AIX / Korn Shell

Hi all, Can someone point me in the right direction for a manual on the various statement options for 'if'. Basically I have a piece of code which says: if ] and I wondered what the -f was. I know the '!' means not equal.. As usual any help much appreciated.. (5 Replies)
Discussion started by: Grueben
5 Replies

4. Shell Programming and Scripting

self-learning! my korn shell problem

i am a beginner i m learning shell by myself i have problem writing a korn shell that takes an absolute pathname to directory and display all ordinary files in the directory ordered by their length. i was thinking use grep ls sort and sed. maybe, i m wrong! can someone tell me? (2 Replies)
Discussion started by: babuda0059
2 Replies

5. Shell Programming and Scripting

korn shell automation problem!

I got the task writting Korn Shell script to automate the tuxedo login so that users neednot have to enter options manually. I have done that using expect tool from the Unix but my manger told me its not secure so you have to do that using Kornshell without using Expect. Here is the way to login to... (0 Replies)
Discussion started by: pareshan
0 Replies

6. AIX

AIX 4.2 Korn shell and grep question

Ho do I find out the verion of the Kron shell on my client`s system ? There is no one to ask. They are not knowledged enough (hard to believe but yes). Also, on that AIX 4.2, I am trying to figure out how to do a grep using a search patter like below but does not seam to work. The '*' do... (11 Replies)
Discussion started by: Browser_ice
11 Replies

7. Shell Programming and Scripting

Pattern manipulation in korn shell script using sed.

Hi, Could any one let me know, how can I cut the last field in below mentioned line. net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.37.0,10.253.0.1 net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.1.0,10.253.0.1 net,-hopcount,0,-netmask,255.255.255.0,,,,,192.168.38.0,10.253.0.1... (3 Replies)
Discussion started by: ajilesh
3 Replies

8. Shell Programming and Scripting

Problem with Korn Shell

My Korn shell script below is giving me the following error: ./test.ksh: 0403-057 syntax error at line 7 : 'then' is not matched. Can anyone provide a quick solution as to why the error is occurring? Thanks. #!/usr/bin/ksh typeset -i RecCount typeset -i RecCount2 RecCount=`db2 -x "select... (23 Replies)
Discussion started by: sasaliasim
23 Replies

9. UNIX for Dummies Questions & Answers

problem extracting substring in korn shell

hi all, I have read similiar topics in this board, but i didn' t find the posting which is the same with the problem i face.. I try to extract string from the end. i try to do this: num=abcdefghij num2=${num:-5} echo $num2 #this should print the last 5 characters (fghij) but it doesn;t... (3 Replies)
Discussion started by: nashrul
3 Replies

10. Shell Programming and Scripting

problem with set command in korn shell

I have to copy an array to a temp variable and back after doing some functions. I am trying to see if it is possible to do without while loops.My closest try was set -A temp ${THE_ARRAY} # restore array after some actions set -A THE_ARRAY ${temp} The problem with above is that, the new... (1 Reply)
Discussion started by: vijay1985
1 Replies
Login or Register to Ask a Question