Sequence generation in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sequence generation in shell
# 8  
Old 12-10-2014
@ tushar.modgil

Your original script wasn't giving you both upper and lower limits before entering the next loop level.

This mod will read each line in turn, extract both limits, and then do the final loop.
Code:
# Start with clean file
> sequence.txt
while read line
do
# send '###' as a marker between series
    echo "###" >> sequence.txt 
    i=$(echo $line | cut -d ',' -f7)
    j=$(echo $line | cut -d ',' -f8)
    for k in $(seq $i $j);
    do
        echo $k >> sequence.txt 
    done
done < test.txt

---------- Post updated at 06:35 PM ---------- Previous update was at 06:06 PM ----------

Quote:
Originally Posted by Don Cragun
Code:
4.02138e+09
4.02138e+09

So, maybe you want something more like:
Code:
cut -d"," -f7,8 < file4 | while IFS=', ' read A B junk; do seq -f '%.0f' $A $B; done

Thanks for this Don Cragun. I found that happening when doing...
Code:
< test.txt mapfile limits
for line in ${limits[*]};
do

in place of...
Code:
while read line
do


Last edited by ongoto; 12-10-2014 at 10:42 PM.. Reason: multiple copies of ------- Post updated ---------
# 9  
Old 12-11-2014
Solution with awk:
Code:
awk -F, '{split ($8,a," "); for (i=$7;i<=a[1];i++) printf "%.0f\n",i}' test.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Will shell script executes in sequence

I have a shell script scheduled in cron job to run at every 1 minute which transfers files to remote machine and then move the files to backup folder. cd /u01/app/ftp_tmp sftp user@hostname <<-EOF cd /home/user/ftp mput * bye EOF mv /u01/app/ftp_tmp/* /u01/app/ftp_bkp Now the problem is... (6 Replies)
Discussion started by: Bhavi
6 Replies

2. Shell Programming and Scripting

Dynamic file generation using shell

I have to generate the file dynamically from the source file based on the below control file. control_file.txt 1,3,5,-1,8,-1,4 The control file contain the position of column which i required from the source file, Example 1 column ,3 column ,5 column ,blank column(-1 indicates blank... (2 Replies)
Discussion started by: rspwilliam
2 Replies

3. 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

4. UNIX for Advanced & Expert Users

Sequence number merged with hypen, shell script

Hello Folks, i have to write shell scripting for given expected output manner. in given input we have to write shell script in such a way that sequence no can b merged/link between start and end digit with hyphen "-" symbol and rest of digit separated by "," Eg : For Input "2 6 7 8 11 12... (9 Replies)
Discussion started by: panchalh
9 Replies

5. Shell Programming and Scripting

Shell scripting for this sequence

KINDLY HELP ME FOR SHELL SCRIPTING FOR THIS TASK. My input file consists of thousands of sequence in this format. The given input file consists of four sequences which are starting with ‘>’ symbol (each sequence shown in different colour for easy understanding). I have to use a command at $... (3 Replies)
Discussion started by: kswapnadevi
3 Replies

6. Shell Programming and Scripting

Shell scripting for this sequence to compare

I have two input files (given below) and to compare each line of the File1 with each line of File2 starts with '>sample1'. If a match occurs and that matched line in the File2 contains another line or sequence of lines starting with "Chr" they have to be displayed in output file with that sample.... (4 Replies)
Discussion started by: hravisankar
4 Replies

7. Shell Programming and Scripting

Shell scripting : Help Me for this sequence

I have two input files (given below) and to compare each line of the File1 with each line of File2 starts with '>sample1'. If a match occurs and that matched line in the File2 contains another line or sequence of lines starting with "Chr" they have to be displayed in output file with that sample.... (9 Replies)
Discussion started by: hravisankar
9 Replies

8. Shell Programming and Scripting

Monitor file generation for an hour using Korn shell script

Hi, I am new to this unix scripting, I got a requirement like.. Files with *.XML extension will be generating in a /home/sample/ folder for every 15 mins. I need to monitor those files in that particular folder for every hour. If no file has been generated in that particular folder for an... (7 Replies)
Discussion started by: siri_886
7 Replies

9. Shell Programming and Scripting

ID generation in sequence

i have an xml tag. The value for the tag should be iterated through out the xml document. eg: <data><id><id><name>a</name><addr>aaa</addr><phnumb>3456</phnumb><state>ca</state><city>ny</city></data>... (6 Replies)
Discussion started by: Sgiri1
6 Replies

10. Shell Programming and Scripting

Sequence number generation on a key column

Hi Folks, Can you help me with this issue: I have to generate the numbers say from 1001 for each record in a file based on a key field, the catch is the generated number should be unique based on key column. (EMP_NUMBER) Example: Input File: EMP_NUMBER EMP_NAME 8908 ... (6 Replies)
Discussion started by: sbasetty
6 Replies
Login or Register to Ask a Question