The time now is Sun 19 May 2013, 23:46
All times are UTC - 4 |
| Author |
Message |
mrbubl3s
Joined: 13 Mar 2010 Posts: 55 Location: %EARTHDIR%
|
Posted: 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!
Last edited by mrbubl3s on Sun 04 Apr 2010, 23:01; edited 1 time in total
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4001 Location: Arizona, U.S.A.
|
Posted: 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
|
|
 |
mrbubl3s
Joined: 13 Mar 2010 Posts: 55 Location: %EARTHDIR%
|
Posted: Sun 04 Apr 2010, 22:57 Post subject:
|
|
Yes! Thank you!
|
|
Back to top
|
|
 |
|
|
|
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.0553s ][ Queries: 11 (0.0145s) ][ GZIP on ] |