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
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 03:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy