I have another problem. I'm trying to extract a string to be used as part of a new file's name. For each type I know either the format of or the placement of the text.
I can't use $1 for pulling out the numerical reference since there may or may not be a space at the end of the character string I want, All I do know is that there will be a lenght to be determined numeric reference at the beginning of each line.
-SAMPLE SOURCE-
11111111111111-dont want
11111111111112-start.*101-01
11111111111113-file 1 text
11111111111114-stop
11111111111115-dont want
11111111111116-start.*101-02
11111111111117-file 2 text
11111111111118-stop
11111111111119-dont want
11111111111120-start.*101-03
11111111111121-file 3 text
11111111111122-stop
.
.
.
On lines that contain the strnig /start/ I want to grab part of the leading number as well as the series number after the "*". Ultimatly I want to use them to create files with the name: Test###-##.############## with the first few files being:
TEST101-01.11111111111112
TEST101-02.11111111111116
etc
I have been trying pattern searches such as /^[0-9]\{14\}]/ but I can't get it to work, much less assign it to a variable for future use.
Here is my code so far
nawk '
BEGIN{prefix=101}
#/start/ {datestamp=/[^[0-9]\{14\}]/}
/start/,/stop/ {file = "test" prefix "." datestamp; print >> file }
/stop/ { if (file != "") close(file) ; ++prefix}
' log1
So far my code is not generating filenames beyond "test" prefix.
Any help is appreciated. I again want to thank Aigles for his help on my other issue!
I can't use $1 for pulling out the numerical reference since there may or may not be a space at the end of the character string I want, All I do know is that there will be a lenght to be determined numeric reference at the beginning of each line.
-SAMPLE SOURCE-
11111111111111-dont want
11111111111112-start.*101-01
11111111111113-file 1 text
11111111111114-stop
11111111111115-dont want
11111111111116-start.*101-02
11111111111117-file 2 text
11111111111118-stop
11111111111119-dont want
11111111111120-start.*101-03
11111111111121-file 3 text
11111111111122-stop
.
.
.
On lines that contain the strnig /start/ I want to grab part of the leading number as well as the series number after the "*". Ultimatly I want to use them to create files with the name: Test###-##.############## with the first few files being:
TEST101-01.11111111111112
TEST101-02.11111111111116
etc
I have been trying pattern searches such as /^[0-9]\{14\}]/ but I can't get it to work, much less assign it to a variable for future use.
Here is my code so far
nawk '
BEGIN{prefix=101}
#/start/ {datestamp=/[^[0-9]\{14\}]/}
/start/,/stop/ {file = "test" prefix "." datestamp; print >> file }
/stop/ { if (file != "") close(file) ; ++prefix}
' log1
So far my code is not generating filenames beyond "test" prefix.
Any help is appreciated. I again want to thank Aigles for his help on my other issue!