Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 20 Apr 2014, 07:04
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
[SOLVED] Having trouble showing more output.
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [3 Posts]  
Author Message
mrbubl3s

Joined: 13 Mar 2010
Posts: 55
Location: %EARTHDIR%

PostPosted: Sun 04 Apr 2010, 01:39    Post subject:  [SOLVED] Having trouble showing more output.
Subject description: In shell scripting.
 

Hello fellow forum members, is there a way in shell script to show a certain line of output with printf?

Example:

# fortune

Once the game is over,
the king and the pawn
go in the same box.

--whoever

How would I show 'go in the same box', instead of just the first line?

and

How do I show all the output?

I know how you get the last line (or first), and/or the last lines up (or the first lines down), using:

<command> | head -2
or
<command> | tail -2

Thanks! Very Happy

Last edited by mrbubl3s on Sun 04 Apr 2010, 23:01; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
sunburnt


Joined: 08 Jun 2005
Posts: 4982
Location: Arizona, U.S.A.

PostPosted: Sun 04 Apr 2010, 16:36    Post subject:  

Hi mrbubl3s; Several ways as usual...

>>> Method #1:
Code:
S1=Once the game is over,
S2=the king and the pawn
S3=go in the same box.

Echo the variables you want to show:
Code:
echo -e $S1\\n$S2\\n$S3

If you have lots of lines to manage put them in an array.

>>> Method #2:
Code:
S='Once the game is over,
the king and the pawn
go in the same box.'

Echo the variable through sed:
Code:
echo "$S" |sed '3!d'

The variable "$S" must be double quoted to preserve the carriage returns ( new lines ).
The number 3 in the sed statement is the line you want shown.
To show more lines use the first and last line you want shown.
All 3 of them:
Code:
echo "$S" |sed '1,3!d'

Just the first 2:
Code:
echo "$S" |sed '1,2!d'

The lines shown must be continuous, you can`t show them at random.
>>> However... Method #1 can show any combination of lines you want it to.
Back to top
View user's profile Send private message 
mrbubl3s

Joined: 13 Mar 2010
Posts: 55
Location: %EARTHDIR%

PostPosted: Sun 04 Apr 2010, 22:57    Post subject:  

Yes! Thank you! Smile
Back to top
View user's profile Send private message Visit poster's website MSN Messenger 
Display posts from previous:   Sort by:   
Page 1 of 1 [3 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0404s ][ Queries: 12 (0.0043s) ][ GZIP on ]