Sponsored Content
Top Forums Shell Programming and Scripting Trying to implement 'more' command Post 302197254 by Cellofan on Tuesday 20th of May 2008 02:39:35 PM
Old 05-20-2008
Trying to implement 'more' command

Hi all, i'm quite new in the UNIX world. So maybe i'm going to ask simple questions but they are unsolvable for me...
I'm trying to implement the 'more' function or kinda of that, for improving my knowledges. But I encountered some problems that i hope u will help me to solve.
The code i developed till now follows below. I put in red the parts that I couldn't manage to implement with some comments.

#!/bin/ksh
clear;
a=$(stty -a|sed -n '2p'|awk '{print $3}'|nawk 'sub(".$","")') #returns the number of rows of the present shell and save it in the variable a
b=$(cat $1|wc -l) #returns the number of lines of the file
c=$(stty -a|sed -n '2p'|awk '{print $6}'|nawk 'sub(".$","")') #returns the number of columns of the present shell and save it in the variable c
count=$a;
temp=1;

while [ $count -le $b ] ; do
bold=`tput smso`
offbold=`tput rmso`
echo "${bold}Press 'c' if you want to continue, 'b' if you want to go back,'q' if you want to quit${offbold} \c"
read ANSW
case "$ANSW" in

[Cc])
e=0;
for <condition>; do #the following cycle must be done for each line that i want to observe
if ( col_line -gt $c ); do #if the number of columns of EACH line is bigger than the number of columns of the shell
d=col_line/$c; #d contains the ratio between the numb of col of the single line and the numb of col of the shell
d=round d; #d must be rounded to the SMALLER nearest integer
e=`expr $e + $d`
fi
done
count=`expr $count - $e` #count will be equal to the exact number of lines
sed -n "$temp,`expr $count - 1` p" $1
temp=$count;
count=`expr $count + $a`
;;
[Bb])
count=`expr $temp -$a + 1`
sed -n "$count,$temp, p" $1;
temp=$count;

;;
[Qq])
exit 1
;;
*) echo You answered a nonsense word, retype the answer
sleep 1
;;
esac

done

The main problems are:
- what is the condition i should put in the while cycle
- what is the condition i should put in the for cycle
- how can i get the value of col_line (number of columns of each line of the text file)
- how can i keep the value of count and temp to use them in case I press 'b'?
- how can i make the written inside 'echo' disappear (as in 'more' command)?

Thanks in advance for answering

Cellofan
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how can i implement rlogin

how can i use a rlogin with out entered a password, someone tell me about configure the next files /.rhosts /etc/hosts.equiv and /etc/hosts but i not sure about that, or there are not enough could you tell me how to do that? (3 Replies)
Discussion started by: jav_v
3 Replies

2. Programming

how does va_arg implement ?

1 . How does va_arg implemented by system? (2 Replies)
Discussion started by: chenhao_no1
2 Replies

3. Shell Programming and Scripting

how to implement this

Hi all, could any of you please help me on my problem.. we are doing FTP (one report out put) from one server to another server through unix shell script program. Due to the network issues, some times FTP process is hanging. So we planned to modify the existing program with the following... (2 Replies)
Discussion started by: kishore_jasthi
2 Replies

4. Shell Programming and Scripting

Trying to implement case

Hi All, My requirement is if the record is starting with 0, then do some processing. if starting with 1, some processing else (not with 0 or 1 ) then do some other processing. i tried the following case "$test" in /^0/) echo "starting with zero ;; /^1/) echo " with one" ;; *) echo... (2 Replies)
Discussion started by: ssunda6
2 Replies

5. Solaris

new - How i can implement Mirroring

Unix is something new for me, I trying learn about it now. I have download the sun virtualbox software and install solaris 10 into it. It is is like wizard with step by step installation guideline. :) NOw how can i implement mirroring(RAID) into the my new SunOS? can anyone give a briefly list... (14 Replies)
Discussion started by: webster5u
14 Replies

6. Shell Programming and Scripting

How to implement this?

hi i have a file like 1,"A","B" 2,"C","D" 1,"E","F" 3,"G","H" in output i need like 3,"G","H" 1,"E","F" 2,"C","D" 1,"A","B" (12 Replies)
Discussion started by: angel12345
12 Replies

7. Shell Programming and Scripting

How to implement a command n times?

I need to run a command n (n >= 100) times and the command running may take about 30 seconds. Can anyone help me with the shell script to achieve this? Thanks in advance. (5 Replies)
Discussion started by: zwei2011
5 Replies

8. Homework & Coursework Questions

How to implement wc command using awk?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here in flwng code \n is not working 2. Relevant commands, code, scripts, algorithms: Files: a.txt This... (0 Replies)
Discussion started by: sidpatil
0 Replies

9. Programming

Implement ps command in C

Hello, could anybody explain how the ps command works? I know something about the proc file system. But I'm still not sure about how it exactly works. Like ps without any option will print out the current user's processes, but it never displays my web browsers such as firefox or my LibreOffice... (3 Replies)
Discussion started by: freedombird9
3 Replies

10. UNIX for Beginners Questions & Answers

How to implement a simple command/code for multiple files?

I have been extracting a row, based on multiple key word from a xls/csv file, by using the following command. I have to implement the same for multiple xls/csv files, therefore please help me to do the same. awk ' { tbp=0 if ($0 ~ keyword1 && k1 == 0) { tbp=1; k1++ } if ($0 ~ keyword2... (2 Replies)
Discussion started by: dineshkumarsrk
2 Replies
F77(3pm)						User Contributed Perl Documentation						  F77(3pm)

NAME
ExtUtils::F77 - Simple interface to F77 libs DESCRIPTION
This module tries to figure out how to link C programs with Fortran subroutines on your system. Basically one must add a list of Fortran runtime libraries. The problem is their location and name varies with each OS/compiler combination! This module tries to implement a simple 'rule-of-thumb' database for various flavours of UNIX systems. A simple self-documenting Perl database of knowledge/code for figuring out how to link for various combinations of OS and compiler is embedded in the modules Perl code. Please help save the world by sending database entries for your system to karl_pgplot@mac.com Note the default on most systems is now to search for a generic 'GNU' compiler which can be g77, gfortran or g95 and then find the appropriate link libraries automatically. (This is the 'Generic' 'GNU' database entry in the code.) The library list which the module returns can be explicitly overridden by setting the environment variable F77LIBS, e.g. % setenv F77LIBS "-lfoo -lbar" % perl Makefile.PL ... SYNOPSIS
use ExtUtils::F77; # Automatic guess use ExtUtils::F77 qw(sunos); # Specify system use ExtUtils::F77 qw(linux g77); # Specify system and compiler $fortranlibs = ExtUtils::F77->runtime; METHODS
The following methods are provided: o runtime Returns a list of F77 runtime libraries. $fortranlibs = ExtUtils::F77->runtime; o runtimeok Returns TRUE only if runtime libraries have been found successfully. o trail_ Returns true if F77 names have trailing underscores. o compiler Returns command to execute the compiler (e.g. 'f77'). o cflags Returns compiler flags. o testcompiler Test to see if compiler actually works. More methods will probably be added in the future. AUTHOR
Karl Glazebrook (karlglazebrook@mac.com). perl v5.10.1 2011-01-01 F77(3pm)
All times are GMT -4. The time now is 06:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy