Problem with character by character reading


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with character by character reading
# 1  
Old 05-06-2012
Problem with character by character reading

Hi friend,
i have the following problem:
when i am writting the below command on the command prompt , its working.
Code:
while read -n 1 ch; do echo "$ch" ; echo "$ch" ; done<file_name.out.

but when i am executing it after saving it in a ksh file, its not working.
Please helppppppppp .. thankss in advance

Last edited by jim mcnamara; 05-06-2012 at 12:18 PM.. Reason: code tags
# 2  
Old 05-06-2012
What is not working? What output do you get? What is your input?
# 3  
Old 05-06-2012
read -n 1 is a bash-ism. ksh88 does not support it.

Care to tell us what 'does not work' means?
# 4  
Old 05-06-2012
@ scrutinizer : i am getting the error as dirty read . input is a simple text file.
@jim mcnamara : i am getting error as dirty read . can you please tel me the korn shell equivalent of the above command?

Thanks a lot guys in advance
# 5  
Old 05-06-2012
What is the exact error?
# 6  
Old 05-07-2012
the exact error is : read: bad option(s)
can you please tel me the korn shell equivalent of the above command?

thanks in advance Smilie
# 7  
Old 05-07-2012
This can be used in a recent ksh93, but not in older version, nor in ksh88. What OS and version are you using and what is your ksh version? It would appear to be ksh88.

Last edited by Scrutinizer; 05-07-2012 at 03:55 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed searches a character string for a specified delimiter character, and returns a leading or traili

Hi, Anyone can help using SED searches a character string for a specified delimiter character, and returns a leading or trailing space/blank. Text file : "1"|"ExternalClassDEA519CF5"|"Art1" "2"|"ExternalClass563EA516C"|"Art3" "3"|"ExternalClass305ED16B8"|"Art9" ... ... ... (2 Replies)
Discussion started by: fspalero
2 Replies

2. Shell Programming and Scripting

Preserve spaces while reading character character

Hi All, I am trying to read a file character by character, #!/bin/bash while read -n1 char; do echo -e "$char\c" done < /home/shak/testprogram/words Newyork is a very good city. Newyorkisaverygoodcityforliving I need to preserve the spaces as thats an... (3 Replies)
Discussion started by: Kingcobra
3 Replies

3. UNIX for Dummies Questions & Answers

Reading character by character - BASH

Hello every one and thanks in advance for the time you will take to think about my problem. I would like to know if it's possible (in BASH) to read a text file character after character. Exactly this is what I would like to do : Txt file : ATGCAGTTCATTGCCAAA...... (~2.5 millions... (3 Replies)
Discussion started by: sluvah
3 Replies

4. Shell Programming and Scripting

Reading a single character from each line of the file

Hi, I should read one character at a fixed position from each line of the file. So how ??? should be substituted in the code below: while read line ; do single_char=`???` echo "$single_char" done < $input_file (8 Replies)
Discussion started by: arsii
8 Replies

5. Shell Programming and Scripting

Deleting all characters from 350th character to 450th character from the log file

Hi All, I have a big log file i want to delete all characters (between 350th to 450th characters) starting at 350th character position to 450th character position. please advice or sample code. (6 Replies)
Discussion started by: rajeshorpu
6 Replies

6. HP-UX

reading password and echoing '*' character on console

hi all, I am using HP-UX system. I want echoing * characters while reading password through keyboard instead of blank space. can u help me for that code? Thanks (1 Reply)
Discussion started by: hari_uctech
1 Replies

7. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

8. Programming

Strange character added when reading to buffer with length of 12

Hi all, I got trouble with reading and writing ( to standard input/output, file, socket whatever...). I will briefly describe it by giving this example. I want to read a long string from keyboard but i don't know how long it is b4. So i need to know the number of character i will read first.... (6 Replies)
Discussion started by: tazan_007
6 Replies

9. Shell Programming and Scripting

Reading password and echo * character

Hi, First of all i am using solaris 10. I want to write a script that ask user to enter password and read the character input from keyboard. The ask to re-enter the password and then if they are match it will accept. But my problem is I want to echo a '*' character instead of the character I... (4 Replies)
Discussion started by: alanpachuau
4 Replies

10. Programming

reading a single character in C

Can anyone help me????? My problem is that i want to read only one charcter from keyboard. Each time my program waits to press enter or ^d. I don't want that. As soon as i press a charcter it should proceed to next statement in program without pressing enter or ^d. please help... (3 Replies)
Discussion started by: alodha
3 Replies
Login or Register to Ask a Question