Cat and read command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cat and read command
# 1  
Old 12-29-2003
Question Cat and read command

Here's what the shell (korn) script is doing:
1. Prompt for input
2. Read a file using the cat and the while read command.
3. Get a field on the record and hold that value in a variable.
4. Within the process, I then need to prompt the user again to ask them if they are sure they want to make a change.
PROBLEM - When I do the second read to prompt user, the value in the read varaible is the record from the file.

CODE:
typeset -u DESC
typeset -u RESPONSE

echo "Enter new type description:\c"
read DESC

cat filename | while read rec
do
type=`echo "$rec" | cut -c1-2`
if [ "$type" = "01" ]
then
#== Change the description ==#
while true
do
echo "Are you sure you want to change the description (Y/N) :\c"
read RESPONSE
if [ $RESPONSE != "Y" ] && [ $RESPONSE != "N" ]
then
echo "\nInvalid response, enter a Y or N \c"
continue
else
break
fi

done

if [ "$RESPONSE" = "Y" ]
then
echo "$type,$DESC" >> new_file
else
echo "$rec" >> new_file
fi

else #== Not an 01==#
echo "$rec" >> new_file
fi

done
# 2  
Old 12-29-2003
Try this:

read RESPONSE < /dev/tty
# 3  
Old 12-29-2003
Computer

Thanks, that worked.

I know dev is a directory. What is tty?Smilie
# 4  
Old 12-29-2003
/dev is a directory that by convention contains only special files. /dev/tty is a special file that refers to your terminal. So no matter which terminal you are using. /dev/tty is your terminal. You can read from it or write to it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Not able read data with cat command

I am trying to read some data form .key file with cat command..but its not displaying data correctly..tried with other commands also still no use.i tried with CAT with SED combination but no use.. Please help me with the command or script. (10 Replies)
Discussion started by: kish_rock
10 Replies

2. Shell Programming and Scripting

Help need on cat command

I have two files as below 1.txt AA 123 CC 145 DD 567 2.txt AA 111 YY 128 CC 144 FF 222 DD 777 ZZ 875 basically 1.txt is updated file, if i do cat 1.txt 2.txt output should be as below o/p (2 Replies)
Discussion started by: Tecnical_help12
2 Replies

3. Shell Programming and Scripting

How can I read variable text files through cat command?

Hi. I'm just wondering how can I read variable text files through cat command. I made a shell script to count frequency of words and array them with variable conditions. It's only working for one file that I wrote in script now. But I want to make it working for every text file when I execute... (2 Replies)
Discussion started by: rlaxodus
2 Replies

4. Shell Programming and Scripting

Read files, lines into array, cat vs open

Hi Everyone, I have a file: a.txt a,b,c,d,6,6,6 1,2,3,d,6,6,6 4,5,6,6,6,6,6 #!/usr/bin/perl use warnings; use strict; my @array = (); ### Load file into array for my $i (split '\n', `cat /tmp/a.txt`) { push @array, ; } It works. But my a.txt have 1million lines, and... (2 Replies)
Discussion started by: jimmy_y
2 Replies

5. Shell Programming and Scripting

help using read in menu script to cat out lines in logs

What is wrong with my menu script? Do I need to continue with the read statements? All I want to do with option 4 is to cat some /var/log/files and awk out a few lines? How do I do that please? $ cat menu.sh ... (11 Replies)
Discussion started by: taekwondo
11 Replies

6. Shell Programming and Scripting

Cat command help

I want to concatenate 100 files to one file and append file name in each record to find out which file it came from for a in $(<shal_group) do cat $a >> bigoutput.group The above code put all files in one file but i want file name appended to each file Record should be like this... (3 Replies)
Discussion started by: pinnacle
3 Replies

7. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies

8. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

9. AIX

cat command

I would like to append some statement into 1 single file so that it can be concatenate together in 1 word. I have tried >> but it will seperate my 2 statement into 2 rows. # cat abc.txt cde.txt > result.txt where abc.txt is "abcde" and cde.txt is "12345" the result should come out as... (3 Replies)
Discussion started by: kwliew999
3 Replies

10. UNIX for Dummies Questions & Answers

using 'cat' to in 'while read line'

Hi, I'm having some trouble reading a file that was 'cat' through a while loop. Can anyone suggest alternatives? what i do is cat filename|grep *.stuff while read line do echo $line ... and other commands done The cat,grep line seems to work correctly, but the script hangs when i add in... (3 Replies)
Discussion started by: chugger06
3 Replies
Login or Register to Ask a Question