Inserting a range of consecutive numbers into a text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Inserting a range of consecutive numbers into a text file
# 1  
Old 03-25-2009
Inserting a range of consecutive numbers into a text file

I have a text file in the following format
....
START
1,1
2,1
3,1
..
..
9,1
10,1
END
....

I want to change to the output to
....
START
1,1
2,1
3,1
..
..
9,1
10,1
11,1
..
..
99,1
100,1
END
.....

With my little knowledge of sed I could come this far.
sed '/START/,/END/' provides a means of addressing the range. But how to add consecutive numbers from 11 to 99 before END???

Btw the file is filled with numbers before START and after END.

Thanks in advance
VNR
# 2  
Old 03-25-2009
Code:
awk '/END/{for(i=11;i<101;i++){print i",1"}}{print}' file

Regards
# 3  
Old 03-25-2009
works like a charm....thanks very much for the fast reply
# 4  
Old 03-27-2009
Code:
i=10
while [ $i -lt 101 ]
do
        echo ${i},1 >> filename
        i=`expr $i + 1`
done

# 5  
Old 03-27-2009
Quote:
Originally Posted by summer_cherry
Code:
i=10
while [ $i -lt 101 ]
do
        echo ${i},1 >> filename
        i=`expr $i + 1`
done

The above code only appends the numbers at the end of filename. I wanted to add the numbers only before END. As I mentioned there are numbers before and after START and END.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check/print missing number in a consecutive range and remove duplicate numbers

Hi, In an ideal scenario, I will have a listing of db transaction log that gets copied to a DR site and if I have them all, they will be numbered consecutively like below. 1_79811_01234567.arc 1_79812_01234567.arc 1_79813_01234567.arc 1_79814_01234567.arc 1_79815_01234567.arc... (3 Replies)
Discussion started by: newbie_01
3 Replies

2. Shell Programming and Scripting

Convert list of numbers to text range

Hi, I'd like to take a list of numbers (with a prefix) and convert to a range, for example: cn001 cn004 cn016 cn017 cn018 cn019 cn020 cn021 cn031 cn032 cn038 cn042 cn043 cn044 cn045 (5 Replies)
Discussion started by: chrissycc
5 Replies

3. Shell Programming and Scripting

Delete all CONSECUTIVE text lines from file shell scripting

Hi I have a text file like below. THe content of the text will vary. Entire text file have four consecutive lines followed with blank line. I want to delete the occurrence of the two consicutive lines in the text file. I don't have pattern to match and delete. Just i need to delete all... (5 Replies)
Discussion started by: RJSKR28
5 Replies

4. UNIX for Dummies Questions & Answers

Sum every 3 consecutive numbers in a column

Dear All, I have a file with only one column. And I want to add every 3 consecutive numbers together and print the result. Input File: 21.1 10 10 55 11 99 10 8 4 Expected Output: 41.1 (5 Replies)
Discussion started by: NamS
5 Replies

5. Shell Programming and Scripting

Disruption of consecutive numbers

I do have a tab delimited file with the following format 200 46 201 67 204 89 205 98 206 89 208 890 210 23 .. ... 100's of rows I would like to output the missing consecutive number of the first column. The expected output will be: (1 Reply)
Discussion started by: Lucky Ali
1 Replies

6. Shell Programming and Scripting

Inserting text into a new file

Hi all, I want to create a file and then insert some text into it. I'm trying to create a .sh script that will create a new python file from a template. Can someone tell me why this won't work, touch $1 | sed -e '1i\Some test code here' Sorry I'm quite new to all this! Just as a side... (3 Replies)
Discussion started by: ahodgson
3 Replies

7. UNIX for Dummies Questions & Answers

how to print out consecutive two line from a text file

the text file like below's input: aaaaaaaaafdsfsda sdfsadfasdfasfds sdfadsf asdfadf asdfa adfsfsafas sdfsfafads asdfasdfsa I want to print out consecutive two line output: aaaaaaaaafdsfsda (1 Reply)
Discussion started by: vincent_W
1 Replies

8. Shell Programming and Scripting

Finding consecutive numbers in version names on a txt file

Hi all. I have a directory which contains files that can be versioned. All the files are named according to a pattern like this: TEXTSTRING1-001.EXTENSION TEXTSTRING2-001.EXTENSION TEXTSTRING3-001.EXTENSION ... TEXTSTRINGn-001.EXTENSION If a file is versioned, a file called ... (10 Replies)
Discussion started by: fox1212
10 Replies

9. Shell Programming and Scripting

read numbers from file and output which numbers belongs to which range

Howdy experts, We have some ranges of number which belongs to particual group as below. GroupNo StartRange EndRange Group0125 935300 935399 Group2006 935400 935476 937430 937459 Group0324 935477 935549 ... (6 Replies)
Discussion started by: thepurple
6 Replies

10. UNIX for Dummies Questions & Answers

inserting uniq sequential numbers at the start of the file

Hi Unix gurus, I have a file. I need to insert sequential number at the starting of the file. Fields are delimited by "|". I know the starting number. Example: File is as follows |123|4test|test |121|2test|test |x12|1test|test |vd123|5test|test starting number is : 120 ... (7 Replies)
Discussion started by: jingi1234
7 Replies
Login or Register to Ask a Question