Simple Unix Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple Unix Question
# 1  
Old 11-24-2005
Simple Unix Question

Hi all,

ok here is my problem, my program below is reading lines in from a file (one at a time) and printing them out. my problem is that i want it to only print out 3 lines at a time on the screen, but the "read value" command in my code isnt working. Whats wrong? & what can i do to get this working?

Thanks all for you replies in advance.

IFS=^
clear
counter=0
file=$1
cat $file |
while read line
do
counter=`expr $counter + 1`
set $line
echo -e "\t\t------------------------------------------------"
echo -e "\t\t| Name: $1 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| Address : $2 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| $3 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| $4 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| PhoneNumber: $5 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| Fax Number: $6 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| E-mail: $7 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| Website: $8 \r\t\t\t\t\t\t\t\t|"
echo -e "\t\t| |"
echo -e "\t\t| o o |"
echo -e "\t\t------------------------------------------------"
echo " "

if [ $counter = 3 ]
then
echo "Hit Enter to continue..."
read value
fi
# 2  
Old 11-25-2005
Code:
IFS=^
clear
counter=0
file=$1
cat $file |
while read line
do
        counter=`expr $counter + 1`
        set $line
        echo -e "\t\t------------------------------------------------"
        echo -e "\t\t|  Name: $1 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|  Address : $2 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|            $3 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|            $4 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|  PhoneNumber: $5 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|  Fax Number: $6 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|  E-mail: $7 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|  Website: $8 \r\t\t\t\t\t\t\t\t|"
        echo -e "\t\t|                                               |"
        echo -e "\t\t|                o              o               |"
        echo -e "\t\t------------------------------------------------"
        echo " "

        if [ $counter = 3 ]
        then
                echo "Hit Enter to continue..."
                read value < /dev/tty
                counter=0
        fi

done

Since read command used here indicates that its input is from a file,
a further read within a while loop will not work.

Hence when using a read within a while loop explicitly mention from where read should get the input
Within the while loop read command value is read from terminal /dev/tty
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

2. Shell Programming and Scripting

Simple question 3

Here I am again~~ I am studying the storing function and dot command. But I found I couldn't load a stored function from a file. This is my command-line and script: $ ls -lsa Total 5 0 drwxr-xr-x+ 1 Administrator None 0 May 9 14:44 . 0 drwxr-xr-x+ 1 Administrator None 0 May 9 10:38 .. 4... (4 Replies)
Discussion started by: franksunnn
4 Replies

3. UNIX for Dummies Questions & Answers

Simple question on unix file permission

As I understand the file permissions in UNIX is basically Owner, group, others Lets assume scott user who's primary group is dev creates a file called test.dat and then grants some privileges on that file... scott@unix-host> echo "this is a test" > test.dat scott@unix-host> chmod 640... (4 Replies)
Discussion started by: luft
4 Replies

4. UNIX for Dummies Questions & Answers

A Simple Question

Hi All, I am new to Unix , I have entered 'cd w' in command prompt and pressed tab key , A tab space is generated instead of listing the folders or files that starts with 'W' . What should i do to get it working:confused: Thanks, Deepak (2 Replies)
Discussion started by: Deepakkumard
2 Replies

5. Shell Programming and Scripting

Simple ls question

i am doing ls -la in the out put , first line is as total 41621 What is this total? (2 Replies)
Discussion started by: Saurabh78
2 Replies

6. UNIX for Dummies Questions & Answers

Some simple question abt Unix kernel

Dear all, I got some questions abt how does the Unix kernel work with the work with the other components. (step by step) Can any body tell me some info abt that? if can provide a example for each question that gonna be perfect! Thank you!!! 1. How file management system work together... (2 Replies)
Discussion started by: melbdavid
2 Replies

7. UNIX for Dummies Questions & Answers

Simple Windows-to-Unix SCP question

Hi, I am fairly new to Unix. My school computers have only UNIX installed on them, and I wish to use them to do some parallel computing. To do so, I need to transfer the files from my Windows computer to my Unix account on a different computer. I am using the SSH login with the Putty client.... (2 Replies)
Discussion started by: Duchesne
2 Replies

8. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

9. UNIX for Dummies Questions & Answers

I have a simple unix question

Hello all, I need to write a little unix script to do some work on multiple files. I need to enter the filenames from the command line (scriptname <filename> <filename>. I have written the code to do double spacing, and some line numbering but it does not take multiple files from the command... (1 Reply)
Discussion started by: smn2003
1 Replies

10. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies
Login or Register to Ask a Question