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 Wed 26 Nov 2014, 05:15
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 Posts_count  
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.
Sub_title: 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

Edited_time_total
Back to top
View user's profile Send_private_message Visit_website MSNM 
sunburnt


Joined: 08 Jun 2005
Posts: 5042
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_website MSNM 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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