Using seq (Or alternative)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using seq (Or alternative)
# 1  
Old 04-28-2010
Using seq (Or alternative)

I usually just browse the forum/google for answers, however I've been stuck on a problem for a number of hours now and I've decided to join up and actually ask I've searched the forum ad naseum in an attempt to find answer to my query, however so far I have been unsuccessful.

I'm no expert infact I've been writing shell scripts for all of 2 days.

Basically I want to read in 3 values, set that to a sequence, output to a file then read the values of various lines in as I want to later on.

Code:
read first 
read increment 
read last 

seq $first $increment $last > output.dat

However, my problem is as such.

When I read in a value of -20.0 it gets set to -20 This is not acceptable for me.

How can I get the format of x.0 bearing in mind sometimes the first value will be x.y

Thanks.

Last edited by Scott; 04-28-2010 at 07:24 PM.. Reason: Added code tags
# 2  
Old 04-28-2010
Hi, gtc, and welcome to the forums.

You can use printf to ensure that numbers have a specified precision:
Code:
printf '%.1f\n' -20
-20.0

For your situation, if you require all numbers to be similarly formated, perhaps:
Code:
seq $(printf '%.1f ' $first $increment $last) > output.dat

Regards,
Alister
# 3  
Old 04-28-2010
Spot on.

It would have made more sense to just join up a few hours ago and ask rather than assure myself I could figure it out. Oh well, what doesn't kill us...

Many thanks for the reply.
# 4  
Old 04-28-2010
Quote:
Originally Posted by gtc
When I read in a value of -20.0 it gets set to -20 This is not acceptable for me.
Depending on your shell, it may not support floating point numbers, and only treat them as strings.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Easy seq Question

Hi! I'm trying to do this: 1 - 2 - 3 - 4 - 5 - I'm using seq for this: seq 1 20 > filename.txt How do I get the "-"? I've tried -f per man but can't get anything to work. Also, is there an easier or better way than using sequence? Thanks! (6 Replies)
Discussion started by: TonyBe
6 Replies

2. Shell Programming and Scripting

awk command to find seq lines

I have a below file FILE.cfg JAN_01 VAR1=4 VAR2=SUM VAR3=PRIVATE JAN_10 VAR1=44 VAR2=GUN VAR3=NATUR JAN_20 VAR1=3 VAR2=TQN VAR3=COMMA code: (JAN_10 is argument passed from script) (6 Replies)
Discussion started by: Roozo
6 Replies

3. UNIX for Dummies Questions & Answers

RNA-seq analysis

I am processing RNA-seq data files that have been aligned using RUM. One of the output files is a *.sam that includes: Unique alignments Non-unique alignments original read files I want to extract only the unique alignments by pulling out alignments that have "IH:i:1" (indicates this read... (2 Replies)
Discussion started by: genGirl23
2 Replies

4. Shell Programming and Scripting

How to show first 0 using seq or +1 count?

Greetings, Using linux based OS and KSH. I m trying to make a simple script to parse some logs to show a count per hour on a specific alarm starting from midnight to the current hour. So I format my "HOUR" variable to show the current time and so I can use it in the following bit of code.... (6 Replies)
Discussion started by: Sekullos
6 Replies

5. Shell Programming and Scripting

sorting a fixed width seq file

I have a file like this... 2183842512010-11-25 15379043 453130325 2386225062010-11-30 4946518 495952336 2386225062010-11-30 4946518 495952345 2386225062010-11-25 262066688 -516224026 2679350512010-11-25 262066688 -516224124 3196089062010-11-25 262066688 203238229... (5 Replies)
Discussion started by: issaq84mohd
5 Replies

6. UNIX for Dummies Questions & Answers

Help with seq (print a series of dates)

Assuming one does not have such luxuries as bash, zsh, jot, rs, perl, etc. what is the most elegant way to print out a formatted date series like this: 01-01-2010 01-02-2010 01-03-2010 ... 02-01-2010 02-02-2010 ... Can I accomplish this with just basic shell builtins and seq, or... (3 Replies)
Discussion started by: uiop44
3 Replies

7. Shell Programming and Scripting

Using Seq As A Variable With Padded Digits

Hi all. Im trying to use a sequence in a while loop like this below. I need it for navigating a year, month, day folder structure where a user can input the start date and have it go to the desired end date. The script will grab a certain file on each day then move onto the next. Ive got all that... (3 Replies)
Discussion started by: Grizzly
3 Replies

8. Shell Programming and Scripting

declaring variable with for $(seq)

Hi guys. i have the following script: 1 #!/bin/bash 2 linkcount=$(grep "/portal" tickets | wc -l) 3 grep "/portal" tickets > links 4 for i in $(seq 1 $linkcount); do 5 echo "BLYAT" 6 let link$i=$(sed -n "$i"p links) 7 echo $ 8 done the problem is, that "let" can`t... (1 Reply)
Discussion started by: neverhood
1 Replies

9. SCO

lp: cannot lock /usr/spool/lpd/printer1/.seq

Hi. I'm receive thats error on my PC. lp: cannot lock /usr/spool/lpd/printer1/.seq This PC is a Windows pc running lpd on port 515. That its means? Thanks. PD. Sorry for my english! (0 Replies)
Discussion started by: sebpes
0 Replies

10. Shell Programming and Scripting

script to loop and check jumping seq.

Hi, Normally, I will manually to use "ll" command to list the following file from \FILE\CACHE\ directory and check the jump seq. Can I write a script to loop or/and check jump seq file (if jumped seq and show "missing seq no" message for me) -rw-rw----+ 1 user develop 14012 Sep 4... (1 Reply)
Discussion started by: happyv
1 Replies
Login or Register to Ask a Question