How to create a new file where each new line contains some text and quoted line/step number?

84 views Asked by At

I want to use a loop while creating a new file where each new line is created by one/single step: some text, then quoted step number, and then something else. I started with this code, but it does not work:

gawk '
{
    for (i = 1; i <= 1000; i++)
        print "begin\""i"\"text"i"end" # how to print a line break?
        >> "path/to/output.txt" 
}'

so I want to see

output.txt:

begin"1"text1end
...
begin"1000"text1000end  

Please, help to solve this.

1

There are 1 answers

5
lyrically wicked On BEST ANSWER

The code needs to be placed inside of BEGIN block:

gawk 'BEGIN {
    for (i = 1; i <= 1000; i++)
        print "begin\""i"\"text"i"end" >> "path/to/output.txt" 
}'