Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have an input file which consists of fixed length (10 characters) lines containing a-z.
For each line, I want to build and print a regexp string that I will use elsewhere.
The regexp string will begin (before processing each line):
'/bin/grep .......... /path/to/some/file'
For each 'x' character in the input file, I want to replace the corresponding dot in the regexp with say the corresponding digit of pi (1415926535).
For example, if a line in input file contains an 'x' in the third character (but not the first and second), the regexp string should become:
'/bin/grep ..1....... /path/to/some/file'
If the next 'x' occurs in the seventh character of the line, then the string should become:
'/bin/grep ..1...6... /path/to/some/file'
I feel like some simple way should exist to do this, but my attempts have just become a mess of code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: string substitution
by choroba (Cardinal) on Feb 23, 2022 at 11:20 UTC | |
|
Re: string substitution
by LanX (Saint) on Feb 23, 2022 at 11:38 UTC | |
by LanX (Saint) on Feb 23, 2022 at 12:41 UTC | |
by Anonymous Monk on Feb 23, 2022 at 12:44 UTC | |
by LanX (Saint) on Feb 23, 2022 at 12:52 UTC |