Sponsored Content
Top Forums Shell Programming and Scripting Fill data if number range is given Post 302881857 by Akshay Hegde on Thursday 2nd of January 2014 11:23:50 AM
Old 01-02-2014
Quote:
Originally Posted by RavinderSingh13
Following may also help for same.


Code:
awk -F"-" '{a=$1; b=$2;} b{for(i=0;i<=NR;i++) {for(;a<=b;a++) print a" ";} print"\n"} !b {print a"\n"}' ORS="" file_name

Output will be as follows.

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

Thanks,
R. Singh
Ravinder you can simplify your code
one for loop also you can remove,so that processing will be faster, since loop for(i=0;i<=NR;i++) does not have effect except time consuming, because after 1st iteration a will be equal to b that is { for(;a<=b;a++) print a" " }. It will simply loop till current NR, look at the following
Code:
$ cat file
100-105
107
108-112

Code:
$ awk '{print "NR--> "NR,$0 OFS}END{print "\n"}' ORS="" OFS="\t" file
NR--> 1    100-105    NR--> 2    107    NR--> 3    108-112

Code:
$ awk -F"-" '{a=$1; b=$2;} b{for(i=0;i<=NR;i++) {print  "looping--> "i" ";for(;a<=b;a++) print a" ";} print"\n"} !b {print  a"\n"}' ORS="" file
looping--> 0 100 101 102 103 104 105 looping--> 1 
107
looping--> 0 108 109 110 111 112 looping--> 1 looping--> 2 looping--> 3

Code:
$ awk -F"-" '{a=$1; b=$2;} b{for(;a<=b;a++) print a" ";print"\n"} !b {print a"\n"}' ORS="" file
100 101 102 103 104 105 
107
108 109 110 111 112


Last edited by Akshay Hegde; 01-02-2014 at 12:30 PM.. Reason: typo
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
All times are GMT -4. The time now is 07:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy