How to remove a defined character on an array variable in a do while statement in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to remove a defined character on an array variable in a do while statement in ksh
# 1  
Old 04-07-2010
How to remove a defined character on an array variable in a do while statement in ksh

I have a korn shell code here on a while do statement which replace the string stored on an array removing double quotes characters on it but it doesn't work.

example record: appointmentDate[1] = "tree" which value should result to tree

Code:
#!/bin/ksh
# Remove " on string records
let recordCount=3
let recordNumber=1
while [ $recordNumber -le $recordCount ]
do
    echo "${appointmentDate[recordNumber]}"
    appointmentDate[recordNumber] = $(echo ${appointmentDate[recordNumber]}|sed -e 's/\"//g')
    echo "${appointmentDate[recordNumber]}"
    let recordNumber=$recordNumber+1
done

any ideas on the correct syntax? need help.

Last edited by pludi; 04-07-2010 at 02:13 AM.. Reason: code tags, please...
# 2  
Old 04-07-2010
There is nothing special about a double quote to sed. Perhaps if you don't backslash escape it, it may work.
# 3  
Old 04-07-2010
Thanks for the help. I got the solution. I only removed the space in the coding from appointmentDate[recordNumber] = $(echo ${appointmentDate[recordNumber]}|sed -e 's/\"//g') to appointmentDate[recordNumber]=$(echo ${appointmentDate[recordNumber]}|sed -e 's/\"//g') and the output was fine now Smilie
# 4  
Old 04-07-2010
Question How to post a new thread?

Hi,
I am a new to this forum and want to create new thread.
Anybody please tell me how to post a new thread ?

thanks in advance.
# 5  
Old 04-07-2010
# 6  
Old 04-07-2010
Bug Thank you so much for your reply.

Thank you so much for your reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

2. Shell Programming and Scripting

Remove a character and assign result to a variable

I am reading lines from a file that contain a number sign (#) before a three or four digit number: #1043 #677 I can remove the '#' and get just the number. However, I then want to assign that number to a variable and use it as part of a path further on in my program: /mydir/10/1043 for... (5 Replies)
Discussion started by: KathyB148
5 Replies

3. Shell Programming and Scripting

Using an array with a case statement in KSH

Hi, I'm really new ro shell scripting (actually any kind of programming) and am pretty sure I'm making a pretty basic error here but I can't for the life of me figure it out. What I'm trying to do is get an array working with a case statement in a KSH script. The code is as follows: ... (3 Replies)
Discussion started by: SReilly
3 Replies

4. Shell Programming and Scripting

how can I check the first character of each variable stored in array

variables are stored in this format D0000, D12345, S1234, D12345 | KestrelPrdV2_0.build.177 - svn 141115 tag as V2.0.0.14 D0000, D12345, S1234, D12345 My question is how can I check the first character of each variable stored in array.It should be start with D or S. Please help... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

5. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

6. Shell Programming and Scripting

How to remove the first character on a string in a variable

Hi all, Does anyone know how to code in ksh that will remove the first character in a string variable and replace that variable without the first character? Example: var1=ktest1 will become var1=test1 var2=rtest2 will become var2=test2 Need help please. (10 Replies)
Discussion started by: ryukishin_17
10 Replies

7. UNIX for Dummies Questions & Answers

How to replace character on defined position

I need to replace the character on 6th position. If this character is 1 I have to repleace it with A, if it is 2 than I have to replace it with B. If it is not 1 or 2 I should not repleace it. input: abcd defg abcd 1efg mnop weac rstu 2bcd i need: abcd defg abcd Aefg mnop weac rstu... (2 Replies)
Discussion started by: necroman08
2 Replies

8. Shell Programming and Scripting

Could someone give me an example of awk accessing array defined in Korn Shell?

As per title and much apprecieated! (2 Replies)
Discussion started by: biglau
2 Replies

9. Shell Programming and Scripting

Return an array of strings from user defined function in awk

Hello Friends, Is it possible to return an array from a user defined function in awk ? example: gawk ' BEGIN{} { catch_line = my_function(i) print catch_line print catch_line print catch_line } function my_function(i) { print "echo" line= "awk" line= "gawk"... (2 Replies)
Discussion started by: user_prady
2 Replies

10. Shell Programming and Scripting

Replace variable with a user defined variable

I have a file that has a list of entries in a column x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl >... (1 Reply)
Discussion started by: ce124
1 Replies
Login or Register to Ask a Question