Fill data if number range is given


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fill data if number range is given
# 1  
Old 10-07-2013
Fill data if number range is given

Hi
I want to get all numbers if number range is given as input.
Eg:

INPUT FILE
Code:
100-105
107
108-112

OUTPUT REQUIRED:
Code:
100 101 102 103 104 105
107
108 109 110 111 112


How can I do it using shell? Smilie

Thanks in advance.

Last edited by Franklin52; 10-07-2013 at 07:50 AM.. Reason: Please use code tags
# 2  
Old 10-07-2013
Please use code tag

Try

Code:
$ cat file
100-105
107
108-112

Code:
$  awk  -F'[-]' '{for(i=$1;i<=c=(NF==1)?$1:$2;i++) printf i OFS ;printf RS}' file

100 101 102 103 104 105 
107
108 109 110 111 112


Last edited by Akshay Hegde; 10-07-2013 at 07:06 AM..
This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 10-07-2013
Code:
awk -F"-" '/^[0-9]/ { print "seq ",$1,(NF==1)?$1:$2,"|paste -s";next} {print "echo ",$0;}' filename | sh

# 4  
Old 10-07-2013
Thank You Akshay & Pravin.
Now it is working beautifully.
# 5  
Old 10-10-2013
Hi Guys,

In the same case, a little different scenario. If the requirement is like :

Input File:
Code:
HELLO 100-105 107 108-112
HI 201 204-209 210

OUTPUT Required:
Code:
HELLO~100 HELLO~101 HELLO~102 HELLO~103 HELLO~104 HELLO~105 HELLO~107 HELLO~108 HELLO~109 HELLO~110 HELLO~111 HELLO~112
HI~201 HI~204 HI~205 HI~206 HI~207 HI~208 HI~209 HI~210

i.e. the first field is prefix to each number.

Thanks in advance.

Last edited by dashing201; 10-10-2013 at 02:30 AM..
# 6  
Old 10-10-2013
And where are the code tags? With 68 post you should know how to do it.
# 7  
Old 10-10-2013
Added code tag !!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fill data in column with previous value

Gents, Kindly help me. I have a file with empty values in selected column, I will like to fill the empty values with the previous value. Example Input file X 4959 30010 66727.00 20457.001 1 1441 66512.00 20234.00 20520.001 X 4959 30010 66727.00 20457.001 145 ... (7 Replies)
Discussion started by: jiam912
7 Replies

2. Shell Programming and Scripting

Range of number from 0.1 to 10.0

Is there a way to create a loop that will output number starting from 0.1 to 10.0 0.1 0.2 0.3 0.4 0.5 .. ... 10.0 This is what i tried. for i in {1..50}; do printf -v i '%02d' $i ; echo "$i"; done That will print 01 02 03 .. .. 50 (9 Replies)
Discussion started by: vietrice
9 Replies

3. Shell Programming and Scripting

Script which fill data in XML file

Hello, I need help for writing a script that fills already generated xml file with data from oracle database and random sequences. For example if we have the following tags: <ns1:message> <ns1:messageId> </ns1:messageId> <ns1:languageCode> </ns1:languageCode>... (10 Replies)
Discussion started by: zb99
10 Replies

4. Shell Programming and Scripting

Fill in missing Data

hello everyone, I have a task to input missing data into a file. example of my data below: Wed Feb 01 09:00:02 EST 2012,,,0.4,0.3,,0.3,,0.3,,0.5,,0.3,,,0.4,0.3, Wed Feb 01 09:00:11 EST 2012,,,,,,,0.2,,,,,,,,,, Wed Feb 01 09:00:22 EST... (23 Replies)
Discussion started by: Nolph
23 Replies

5. Shell Programming and Scripting

fill in last column of data

Hello, I am fairly new to awk, and I have the following problem. My file has missing data in the last column, and the program I am pre-processing this file for cannot interpret correctly shortened rows (it just wraps the data around). Is there a way to force awk to create the same... (6 Replies)
Discussion started by: timert34
6 Replies

6. Shell Programming and Scripting

How to fill data from other file and get some output

Greetings, I have a hard time creating a large number of user profiles in a database. The data file looks like this : 01/01/80 Mitch Conley . . . . And I need to put the output into: Name: Mitch Surname: Conley Birthday: 01/01/80 Thanks in advance! (3 Replies)
Discussion started by: hemo21
3 Replies

7. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

8. Shell Programming and Scripting

Number range for SSNs

Hi All. I have a file that has an ID Number field....some of the ID Numbers are actual SSNs. ...does anyone know the range that SSNs may be...this is what I have found so far poking around SSN info sites.... greater than 001-01-0000 and less than 770-00-0000. Does anyone know this to be... (1 Reply)
Discussion started by: lyoncc
1 Replies

9. UNIX for Dummies Questions & Answers

how to fill the name of the spread sheet as a cell's data

In open office spreadsheet, i would like to fill a cell with the name of the spread sheet. That is if the file name of spread sheet is, team.ods, then i have to fill a specific cell with that name 'team'. How to do that ? I have more spread sheets to be created, so i want it to be done... (0 Replies)
Discussion started by: thegeek
0 Replies

10. Shell Programming and Scripting

Fill in missing numbers in range

I need to edit a list of numbers on the following form: 1 1.0 2 1.4 5 2.1 7 1.9 I want: 1 1.0 2 1.4 3 0.0 4 0.0 5 2.1 6 0.0 7 1.9 (i want to add the missing number in column 1 together with 0.0 in column 2). I guess it is rather trivial but i didn't even manage to read column... (5 Replies)
Discussion started by: bistru
5 Replies
Login or Register to Ask a Question