Sponsored Content
Top Forums Shell Programming and Scripting print number pyramid with for loop in unix Post 302420548 by ygemici on Wednesday 12th of May 2010 02:55:21 AM
Old 05-12-2010
PHP

Code:
#!/bin/ksh
 
for i in {1..5} ; do
j=$i
  while [[ $(( j -= 1 )) -gt -1 ]] ; do
       a=$a$i
    done
echo "$a"
a=""
done

Code:
# ./pyramid
1
22
333
4444
55555

 

10 More Discussions You Might Find Interesting

1. HP-UX

Print Problem in UNIX. Need to know the option to specify the print paper size

Hi, Could any one please let me know what is the option available in UNIX to print by specifying the paper size? We are using Unix11i. I could n't see any option specified in the 'lp' command to print the report by specifying the size of the paper. It would be of great help to me, if... (1 Reply)
Discussion started by: ukarthik
1 Replies

2. UNIX for Dummies Questions & Answers

How to ignore characters and print only number using unix?

say D45H E67H G779K F8888U T66Y Y333U output shud be like 45 67 779 8888 66 333 (5 Replies)
Discussion started by: cdfd123
5 Replies

3. Shell Programming and Scripting

to print number one less than actual number

suppose we have a file which contains 34 45 56 77 55 66 54 67 so output shud be like 33 44 55 76 54 65 53 66 (4 Replies)
Discussion started by: cdfd123
4 Replies

4. UNIX for Dummies Questions & Answers

How do you print the number of processes that each user is currently running in Unix?

Ok, so I know there's a way to do this, but I've been trying to find out all afternoon with no luck. I think it should print out something like this: 1 bin 2 daemon 6 duo Where the numbers on the left are the number of processes being run by the user whose name is listed on the right. Is... (4 Replies)
Discussion started by: Duo11
4 Replies

5. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

6. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

7. Shell Programming and Scripting

Parsing log file and print latest number in loop

Hello All, I have an awk script which parses my log file and prints number grepping from a specific line/pattern, now i have to come with a shell script to continue reading the log untill the job is completed, which i would know while reading session log untill process encounters a final... (1 Reply)
Discussion started by: Ariean
1 Replies

8. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

9. AIX

UNIX ksh - To print the PID number and repeat count

This question is asked in an interview today that I have to return output with each PID number and the count of each PID number logged today. Here is the script that I have written. Can you confirm if that would work or not. The interviewer didn't said if my answer is correct or not. Can someone... (5 Replies)
Discussion started by: Subodh Kumar
5 Replies

10. UNIX for Beginners Questions & Answers

Print number of lines for files in directory, also print number of unique lines

I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with: wc -l *|sort 15263 Image.txt 16401 reference.txt 40459 richtexteditor.txt How can I also print the number of unique lines in each file? 15263 1401 Image.txt 16401... (15 Replies)
Discussion started by: spacegoose
15 Replies
LOSETUP(8)						       System Administration							LOSETUP(8)

NAME
losetup - set up and control loop devices SYNOPSIS
Get info: losetup loopdev losetup -l [-a] losetup -j file [-o offset] Delete loop: losetup -d loopdev... Delete all used loop devices: losetup -D Print name of first unused loop device: losetup -f Setup loop device: losetup [-o offset] [--sizelimit size] [-p pfd] [-rP] {-f[--show]|loopdev} file Resize loop device: losetup -c loopdev DESCRIPTION
losetup is used to associate loop devices with regular files or block devices, to detach loop devices and to query the status of a loop device. If only the loopdev argument is given, the status of the corresponding loop device is shown. Note that the old output format (e.g. losetup -a) with comma delimited strings is deprecated in favour of the --list output format (e.g. losetup -a -l). OPTIONS
+The size and offset arguments may be followed by the multiplicative +suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB, PiB, EiB, ZiB and YiB +(the "iB" is optional, e.g. "K" has the same meaning as "KiB") or the suffixes +KB=1000, MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB. -a, --all show status of all loop devices. Note that not all information are accessible for non-root users. See also --list. The old output format (as printed without --list) is deprecated. -c, --set-capacity loopdev force loop driver to reread size of the file associated with the specified loop device -d, --detach loopdev... detach the file or device associated with the specified loop device(s) -D, --detach-all detach all associated loop devices -f, --find find the first unused loop device. If a file argument is present, use this device. Otherwise, print its name -h, --help print help -j, --associated file show status of all loop devices associated with given file -l, --list if a loop device or the -a option is specified, print default columns for either the specified loop device or all loop devices, default is to print info about all devices. -o, --offset offset the data start is moved offset bytes into the specified file or device -O, --output columns specify which columns are to be printed for the --list output --sizelimit size the data end is set to no more than size bytes after the data start -P, --partscan force kernel to scan partition table on newly created loop device -r, --read-only setup read-only loop device --show print device name if the -f option and a file argument are present. -v, --verbose verbose mode ENCRYPTION
Cryptoloop is no longer supported in favor of dm-crypt. For more details see cryptsetup(8). RETURN VALUE
losetup returns 0 on success, nonzero on failure. When losetup displays the status of a loop device, it returns 1 if the device is not con- figured and 2 if an error occurred which prevented from determining the status of the device. FILES
/dev/loop[0..N] loop block devices /dev/loop-cotrol loop control device EXAMPLE
The following commands can be used as an example of using the loop device. # dd if=/dev/zero of=~/file.img bs=1MiB count=10 # losetup --find --show ~/file.img /dev/loop0 # mkfs -t ext2 /dev/loop0 # mount /dev/loop0 /mnt ... # umount /dev/loop0 # losetup --detach /dev/loop0 AUTHORS
Karel Zak <kzak@redhat.com>, based on original version from Theodore Ts'o <tytso@athena.mit.edu> AVAILABILITY
The losetup command is part of the util-linux package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux/. util-linux July 2003 LOSETUP(8)
All times are GMT -4. The time now is 11:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy