Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Insert the line number from text file to filename output Post 303024566 by Peasant on Thursday 11th of October 2018 05:04:19 AM
Old 10-11-2018
Try this :
Code:
while read word; do
i=$((i+1))
  convert  canvas.jpg \
\( -size 350x350 -background none \
-fill white -gravity center caption:"$word" -trim +repage -depth 8 \) \
-gravity center -composite $i.jpg
done < words.txt

cat and pipe is not needed here.

Regards
Peasant.
This User Gave Thanks to Peasant For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert text file at a certain line.

I need to insert a file called temp_impact (which has about 15 lines in it) to a file called 11.23cfg starting at line 33. I searched the forums and found the sed '34i\ test' 11.23cfg > newfile That will enter word test at the appropriate line, but i need the entire file dumped there. Any... (4 Replies)
Discussion started by: insania
4 Replies

2. UNIX for Dummies Questions & Answers

How to grep / zgrep to output ONLY the matching filename and line number?

Hi all, I am trying to zgrep / grep list of files so that it displays only the matching filename:line number and does not display the whole line, like: (echo "1.txt";echo "2.txt") | xargs zgrep -no STRING If I use -o option, it displays the matching STRING and if not used, displays the... (3 Replies)
Discussion started by: vvaidyan
3 Replies

3. Shell Programming and Scripting

How to insert some constant text at beginig of each line within a text file.

Dear Folks :), I am new to UNIX scripting and I do not know how can I insert some text in the first column of a UNIX text file at command promtp. I can do this in vi editor by using this command :g/^/s//BBB_ e,g I have a file named as Test.dat and it containins below text: michal... (4 Replies)
Discussion started by: Muhammad Afzal
4 Replies

4. Shell Programming and Scripting

Insert text at line number

I wrote a script to grep for a closing XML node. Then I need it to navigate up a line and insert some XML. Then go to the next occurrance. I have this INSERT_NODE='<QUANTITATIVE NAME="'${QR_NAME}'" QUANT="1" />' GREP_FOR='</JOB>' TMP_FILE=/tmp/lineArray.$$ if ]; then continue else ... (7 Replies)
Discussion started by: J-Man
7 Replies

5. Shell Programming and Scripting

Insert output into file at line number

I need to insert the output of a script into a specific line number of a txt file. I've read the Sed man page and searched the forums and it's not immediately clear how I would go about doing this. (4 Replies)
Discussion started by: pluto7777
4 Replies

6. Shell Programming and Scripting

Insert a variable to a text file after fixed number of lines

Hi, I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines.. Please help me on this.. Thanks in Advance, Amrutha (3 Replies)
Discussion started by: amr89
3 Replies

7. UNIX for Dummies Questions & Answers

Insert a line in a text file

I want to insert a line with text after the 9th line of a text file. How would I do this using sed or awk? (2 Replies)
Discussion started by: lost.identity
2 Replies

8. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

9. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies

10. Shell Programming and Scripting

Insert text at the beginning of every even number line

i am trying to insert text at the beginning of every even number line with awk i can do it with odd number lines with this command awk 'NR%2{$0="some text "$0}1' filehow can i edit this command thanks (5 Replies)
Discussion started by: bob123
5 Replies
SDL::Tutorial::LunarLander(3)				User Contributed Perl Documentation			     SDL::Tutorial::LunarLander(3)

NAME
Lunar Lander - a small tutorial on Perl SDL INTRODUCTION
This is a quick introduction to Games, Perl, and SDL (Simple DirectMedia Layer, a cross-platform multimedia programming library). We'll write a small game -- Lunar Lander -- in 100 lines of code, or less. CREATING A DEMO You can see the final version of the demo code by doing: perl -MSDL::Tutorial::LunarLander=lander.pl -e1 this will create all three files used in the tutorial: FIRST VERSION We'll start with a text version of the game. "What?", you may ask. "I thought it was a SDL tutorial". Yes, it is -- thank you for reminding me. But we'll leave the SDL part for later. We must build the game logic first! One of the traps of game programming is focusing too much on the interface. If we start with a simpler simulation, we can worry with the presentation later. So, here's the initial code: #!/usr/bin/perl use strict; use warnings; my $height = 1000; # m my $velocity = 0; # m/s my $gravity = 1; # m/s^2 my $t = 0; while ( $height > 0 ) { print "at $t s height = $height m, velocity = $velocity m/s "; $height = $height - $velocity; $velocity = $velocity + $gravity; $t = $t + 1; } if ( $velocity > 10 ) { print "CRASH!!! "; } else { print "You landed on the surface safely! :-D "; } Run the code and you'll see something like this: at 0 s height = 1000 m, velocity = 0 m/s at 1 s height = 1000 m, velocity = 1 m/s at 2 s height = 999 m, velocity = 2 m/s at 3 s height = 997 m, velocity = 3 m/s at 4 s height = 994 m, velocity = 4 m/s at 5 s height = 990 m, velocity = 5 m/s ... at 43 s height = 97 m, velocity = 43 m/s at 44 s height = 54 m, velocity = 44 m/s at 45 s height = 10 m, velocity = 45 m/s CRASH!!! "What happened? How do I control the ship???" CONTROLLING THE SHIP The problem with our first spaceship is that it had no controls! So, let's fix this problem, making the spaceship scriptable. (We could write some code to handle keyboard and joysticks now, but an scriptable spaceship will be easier to start. Remember, focus on the game logic!) So, create add this simple script to the end of your file: __DATA__ at 41s, accelerate 10 m/s^2 up at 43s, 10 m/s^2 at 45s, 10 at 47s, 10 at 49s, 10 The script is straightforward: it simply states a time when we will push the spaceship up with a given acceleration. It accepts free text: any two numbers you type will work. We can parse the script using this regular expression: my $script_re = qr/(d+) D+ (d+)/x; And we can build a hash of ( time => acceleration ) with: my %up = map { $_ =~ $script_re } <DATA>; So the middle section of the program will become: my $script_re = qr/(d+) D+ (d+)/x; my %up = map { $_ =~ $script_re } <DATA>; while ( $height > 0 ) { print "at $t s height = $height m, velocity = $velocity m/s "; if ( $up{$t} ) { my $a = $up{$t}; print "(accellerating $a m/s^2) "; $velocity = $velocity - $a; } $height = $height - $velocity; $velocity = $velocity + $gravity; $t = $t + 1; } That's it! Try to run the program, and the ship should land safely: ./lunar.pl autopilot.txt at 0 s height = 1000 m, velocity = 0 m/s at 1 s height = 1000 m, velocity = 1 m/s at 2 s height = 999 m, velocity = 2 m/s at 3 s height = 997 m, velocity = 3 m/s at 4 s height = 994 m, velocity = 4 m/s at 5 s height = 990 m, velocity = 5 m/s ... at 54 s height = 19 m, velocity = 4 m/s at 55 s height = 15 m, velocity = 5 m/s at 56 s height = 10 m, velocity = 6 m/s at 57 s height = 4 m, velocity = 7 m/s You landed on the surface safely! :-D Cool, but... HOW ABOUT THE GRAPHICS? Okay, okay... now that we have a working prototype, we can work on the graphics. But, first of all, we'll need... THE GRAPHICS Yes, the graphics. We won't use anything fancy here, just two images: a large one, for the background, and a smaller one for the spaceship. Create the images using the Gimp, or use the images provided by this tutorial; Save these images in a subdirectory called "images": (""images/background.jpg"" and ""images/ship.png""). USING SDL First step: use the required libraries: use SDL; #needed to get all constants use SDL::App; use SDL::Surface; use SDL::Rect; Second step: initialize "SDL::App": my $app = SDL::App->new( -title => "Lunar Lander", -width => 800, -height => 600, -depth => 32, ); Third step: load the images and create the necessary "rectangles": my $background = SDL::Surface->new( -name => 'images/background.jpg', ); my $ship = SDL::Surface->new( -name => 'images/ship.png', ); my $background_rect = SDL::Rect->new( -height => $background->height(), -width => $background->width(), ); my $ship_rect = SDL::Rect->new( -height => $ship->height(), -width => $ship->width(), ); Fourth step: create a sub to draw the spaceship and background: sub draw { my ( $x, $y ) = @_; # spaceship position # fix $y for screen resolution $y = 450 * ( 1000 - $y ) / 1000; # background $background->blit( $background_rect, $app, $background_rect ); # ship my $ship_dest_rect = SDL::Rect->new( -height => $ship->height(), -width => $ship->width(), -x => $x, -y => $y, ); $ship->blit( $ship_rect, $app, $ship_dest_rect ); $app->update($background_rect); } Note that this sub first combines all the bitmaps, using a blit ("Block Image Transfer") operation -- which is quite fast, but does not update the display. The combined image is displayed in the last line. This process of combining first, and displaying later, avoids that annoying fading between cycles ("flickering"). Finally, add the following lines to the end of the main loop, so that we call the "draw()" function with the correct spaceship coordinates: while ( $height > 0 ) { # ... draw( 100, $height ); $app->delay(10); } That's it! Run the program and watch the spaceship landing safely on the surface of the moon. COPYRIGHT &; LICENSE Copyright 2009 Nelson Ferraz, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.1 2010-07-05 SDL::Tutorial::LunarLander(3)
All times are GMT -4. The time now is 08:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy