• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with bash  RSS feed

 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem. I need to write a bash script that works like the more command in unix. I really don't know where to start could you help or recommend a bash script board where i could.
thanks in advance.
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to do that differs from the 'more' command? you should be able to use 'more' in your bash script if it's available.
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you don't have more use less.
Anyway, what are you tring to do?
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I guess I should have been more clear on what i'm trying to do. You see I am in a unix shell programming class and i have been given a project to create a bash file that runs like the more command when used on a file. Displaying one page at a time. also i cant call the more command within my file or use cut or paste.
I can't remember the command as i type this but i know there is a command to display a file whitch sort of like the more command but with numbers preceeding each line. I think i can write a loop to print out only 80 lines that way.
[ May 15, 2003: Message edited by: kevin comario ]
 
Bhushan Jawle
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use "less" in ur script if you not allowed to use "more". In fact "less" is more than "more" , check the man pages for differences
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks do you think i could also use grep -n, or sed to read in to the file.
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can tell you that the command that numbers each line of a file is 'nl', and that the suggestion to use 'less -N' as an alternative is a good one.
[ May 16, 2003: Message edited by: George Brown ]
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your help but I asked and also not allowed to use the less command.
here is what i have so far:

The problem I'm having is that anything with a space is considered a new line. so instead of getting for instance "Hello to all" I get:
Hello
to
all.
could you tell me how to fix this problem.
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a new question is there anyway I can get sed to start at a certain line number?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps a combination of "wc -l" (how many lines do you have), "head -x" (grab the top 'x' lines) and "tail -x" (grab the bottom 'x' lines).
So to display lines 15 through 30:
<code><pre> head -30 $1 | tail -15 </pre></code>
Regards, Andrew
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For numbering lines there's the nl command. nl has many options. For simple numbering every line I use cat -n
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!