Sponsored Content
Full Discussion: generate a sequence
Top Forums Shell Programming and Scripting generate a sequence Post 302514321 by sk1418 on Friday 15th of April 2011 11:28:07 AM
Old 04-15-2011
python script:
PHP Code:

#!/usr/bin/python

mtn=[]
l=[]
def printSeq(n):
    global 
l
    l 
range(1,n+1)
    
length len(l)
    global 
mtn
    mtn 
= [str(x)+"->"+str(x+1) for x in l if x<l[-1]]
    for 
x in mtn:
        print 
x

    
for x in range(2length):
        print 
"" # empty line
        
for e in range(length):
            if 
e+xlength:
                
generateOtherSeq(l[e:x+e+1])
    
def generateOtherSeq(myl):
    for 
i in range(len(myl)):
        
ll = list(myl)
        if 
i+len(myl):
            
ll[i] = mtn[l.index(myl[i])]
            
ll.remove(ll[i+1])
            print 
",".join([str(x) for x in ll])
         

printSeq(5
you can change the last line "5" to any number you like. for example "7" will give you this output:
Code:
kent$ python pyseq.py
1->2
2->3
3->4
4->5
5->6
6->7

1->2,3
1,2->3
2->3,4
2,3->4
3->4,5
3,4->5
4->5,6
4,5->6
5->6,7
5,6->7

1->2,3,4
1,2->3,4
1,2,3->4
2->3,4,5
2,3->4,5
2,3,4->5
3->4,5,6
3,4->5,6
3,4,5->6
4->5,6,7
4,5->6,7
4,5,6->7

1->2,3,4,5
1,2->3,4,5
1,2,3->4,5
1,2,3,4->5
2->3,4,5,6
2,3->4,5,6
2,3,4->5,6
2,3,4,5->6
3->4,5,6,7
3,4->5,6,7
3,4,5->6,7
3,4,5,6->7

1->2,3,4,5,6
1,2->3,4,5,6
1,2,3->4,5,6
1,2,3,4->5,6
1,2,3,4,5->6
2->3,4,5,6,7
2,3->4,5,6,7
2,3,4->5,6,7
2,3,4,5->6,7
2,3,4,5,6->7

1->2,3,4,5,6,7
1,2->3,4,5,6,7
1,2,3->4,5,6,7
1,2,3,4->5,6,7
1,2,3,4,5->6,7
1,2,3,4,5,6->7


Last edited by sk1418; 04-15-2011 at 12:34 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Escape sequence

Hi, I have got an application through which an user will submit an address like "c:\tuser\abc". This application calls a script and passes the address to the scripts positional parameter say $1. So $1 should contain "c:\tuser\abc", but when $1 is echoed the "\t" and "\a" are interpreted to... (4 Replies)
Discussion started by: puspendu
4 Replies

2. UNIX for Dummies Questions & Answers

Generate a Sequence like in Oracle

#!/usr/bin/ksh ValUniqueNo=0 export ValUniqueNo FnGenerateUniqueNo() { (( ValUniqueNo = $ValUniqueNo + 1 )) echo $ValUniqueNo export ValUniqueNo=$ValUniqueNo } echo k1=`FnGenerateUniqueNo` echo k2=`FnGenerateUniqueNo` kindly consider the above script. it is required that when... (1 Reply)
Discussion started by: keshav_rk
1 Replies

3. Shell Programming and Scripting

To grep in sequence

Hi, I have a log file containg records in sequence <CRMSUB:MSIN=2200380,BSNBC=TELEPHON-7553&TS21-7716553&TS22-7716553,NDC=70,MSCAT=ORDINSUB,SUBRES=ONAOFPLM,ACCSUB=BSS,NUMTYP=SINGLE; <ENTROPRSERV:MSIN=226380,OPRSERV=OCSI-PPSMOC-ACT-DACT&TCSI-PPSMTC-ACT-DACT&UCSI-USSD;... (17 Replies)
Discussion started by: helplineinc
17 Replies

4. Shell Programming and Scripting

ls all files in sequence. How to?

Hi, all: Newbie questions: For example, if I have 6 files, respectively named as: How to "ls" all files in sequence of two ways? 1) The first way is according to the sequence of the natural number. Say, the same sequence as shown as they are given. 2) The second way is default... (2 Replies)
Discussion started by: jiapei100
2 Replies

5. Shell Programming and Scripting

Check Sequence

* Expiry DATE: * Address1: Address2: Address3: Address4: Address5: * PO_ref_number: aadad HolderId_1: HolderId_2: HolderId_3: HolderId_4: * adad: 00000 ada: 00000 adad: RANDOM adad: RANDOM ****************************** (4 Replies)
Discussion started by: arunshankar.c
4 Replies

6. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

7. Red Hat

Rm -rf * sequence

If I run rm -rf * command under one parent directory. /data > rm -rf * Is there anyway to know which files will be deleted first ? Start using code tags please, ty. (2 Replies)
Discussion started by: sameermohite
2 Replies

8. Shell Programming and Scripting

Script to generate sequence of numbers

I need awk script to generate part number sequencing based on data in multiple columns like below Input File --------- Col A|Col B|Col C| 1|a|x| 2|b|y| |c|z| | |m| | |n| And out put should be like 1ax 1ay 1az 1am 1an 1bx 1by (6 Replies)
Discussion started by: aramacha
6 Replies

9. Shell Programming and Scripting

Sequence extraction

i want to extract specific region of interest from big file. i have only start position, end position and seq id, see my query is: I have file1 is this >GL3482.1 GAACTTGAGATCCGGGGA GCAGTGGATCTCCACCAG CGGCCAGAACTGGTGCAC CTCCAGGCCAGCCTCGTC CTGCGTGTC >GL3550.1... (14 Replies)
Discussion started by: harpreetmanku04
14 Replies

10. BSD

Mcookie, pkg -l to generate random sequence

I am setting this thread to this bsd forum, though it may fit into bash. But as using bsd and the terminal, I would like to generate a random sequence of alphanumerical digits, such as I use to do so on linux by typing just mcookiethis one gives me a pretty random password, but it does not on bsd... (0 Replies)
Discussion started by: 1in10
0 Replies
All times are GMT -4. The time now is 05:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy