Visit Our UNIX and Linux User Community


Sed issue in K Shell programming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sed issue in K Shell programming
# 1  
Old 02-25-2008
Sed issue in K Shell programming

I am doing the following script in k shell

sed -i 's/FILENAME/$i/g' TEST/test$j.ctl > TEST/control$j.ctl

In the file it replaces $i for all FILENAME, it doesnot replace with the value of i. I put single quotes like below

sed -i 's/FILENAME/'$i'/g' TEST/test$j.ctl > TEST/control$j.ctl

I get following error

sed: -e expression #1, char 13: Unknown option to `s'

I did following

sed 's/FILENAME/'$i'/g' TEST/test$j.ctl > TEST/control$j.ctl
same error and it created 0 bytes control$j.ctl

Please help..
# 2  
Old 02-25-2008
Simply use double quotes instead of single quotes:

Code:
sed -i "s/FILENAME/$i/g" TEST/test$j.ctl > TEST/control$j.ctl

Single quotes prevents variable expansion.
# 3  
Old 02-25-2008
Nope same error

sed: -e expression #1, char 14: Unknown option to `s'

sed -i "s/FILENAME/$i/g" TEST/test$j.ctl > TEST/control$j.ctl

sed -i "s/FILENAME/'$i'/g" TEST/test$j.ctl > TEST/control$j.ctl

Tried both but same error

using #!/bin/ksh shell
# 4  
Old 02-25-2008
Oh sorry. Now I don't have ksh available for testing and, to be honest, I don't use it often and don't know it very well.
But it seems strange to me that a basic variable expansion doesn't work in ksh like in bash or sh Smilie
# 5  
Old 02-25-2008
Hi,

Please check the following syntax and let me know it is correct or not

sed 's/FILENAME/'${i}'/ig' filename >filename1

or

sed "s/FILENAME/'${i}'/ig" TEST/test$j.ctl > TEST/control$j.ctl
btech_raju
# 6  
Old 02-25-2008
robotronic's answer works.
Is that the only line you have in the script?
# 7  
Old 02-25-2008
nope it did not work

Previous Thread | Next Thread
Test Your Knowledge in Computers #305
Difficulty: Easy
A regular expression is an integer array that can be used to describe several sequences of characters.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl programming issue

Dears, I want to print filename and count of each file in perl but failing to implement. `find $srcFolder -maxdepth 1 -type f -name "*$workDate*$fileExt" -exec sh -c ' && printf "$workDate|%s|%s\n" "$(wc -l<"$0")" *$workDate*$fileExt' {} \ >> /Sadique/filelog.out \\; 2> /dev/null`; ... (2 Replies)
Discussion started by: sadique.manzar
2 Replies

2. UNIX for Advanced & Expert Users

AIX runtime programming issue

I hope my title is accurate enough. I have a product that we port to various UNIX platforms. It is known to run on AIX but using the IBM compiler from years ago. Recently we got a different used AIX P5 platform running AIX 5.3 and we setup the GCC compiler (4.4.5 I think). C and C++ source code.... (5 Replies)
Discussion started by: Pug
5 Replies

3. Shell Programming and Scripting

Shell Programming

Hi, I am using two files - one file contains list of service name , other file contains commands for each of these service name . I have to read each service name and check this string in 1.cfg file , if it exists , then i have to read another file (commands file ) and take the string and... (2 Replies)
Discussion started by: santhoshks
2 Replies

4. Shell Programming and Scripting

Linux shell programming performance issue

Hi All, can any one help me on this please. Replace sting in FILE1.txt with FILE2.txt. FILE1.txt record must have at least one state is repeated once.But need to replace only from second occurrence in record in FILE1.txt Condition: order of searching the records in FILE2.txt is impartent.... (8 Replies)
Discussion started by: ureddy
8 Replies

5. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

6. Shell Programming and Scripting

Need help with programming issue

I need a UNIX shellscript command that will remove the 'Paragraph' mark from a simple text file. The Paragraph mark I'm referring to is the special character you can see in a WORD documant (similar to a backwards 'P') when you select the Show Paragraph Marks icon. If someone can give me the... (6 Replies)
Discussion started by: varefump
6 Replies

7. Shell Programming and Scripting

SED programming

Hi Folks, I have one file which contains the data like below. gggsdvrwdtydjnnc%vhdskl;jf;whjfuyijfnv,m%jkgsjkfsjkjdlkl%gjksdhfljkfjkj% I want to replace % to the Line feed. I mean the result should be like below. gggsdvrwdtydjnnc vhdskl;jf;whjfuyijfnv,m jkgsjkfsjkjdlkl... (12 Replies)
Discussion started by: pradeesh
12 Replies

8. Shell Programming and Scripting

Sed & awk programming

Hi all, can anyone have sed & awk programming doc..so that to learn it easier.. (1 Reply)
Discussion started by: gk2009
1 Replies

9. Shell Programming and Scripting

Issue with a sed one liner variant - sed 's/ ; /|/g' $TMP1 > $TMP

Execution of the following segment is giving the error - Script extract:- OUT=$DATADIR/sol_rsult_orphn.bcp TMP1=${OUT}_tmp1 TMP=${OUT}_tmp ( isql -w 400 $dbConnect_OPR <<EOF select convert(char(10), s.lead_id) +'|' + s.pho_loc_type, ";", s.sol_rsult_cmnt, ";", +'|'+ s.del_ind... (3 Replies)
Discussion started by: kzmatam
3 Replies

10. Shell Programming and Scripting

Shell Programming

Provides a menu structure that allows a user to select several options - input a name and address, lookup a name and address, delete a name and address, and print a formatted report from a text database (note: this requirement assumes that you will use the program to create a database, though in... (1 Reply)
Discussion started by: DonOmar
1 Replies

Featured Tech Videos