|
Home > Archive > Unix Shell > November 2006 > file editting (shell)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
file editting (shell)
|
|
| sahilbahri@gmail.com 2006-11-30, 7:27 am |
| Hi,
I need to open a text file with classes declared as:
class "CL1" ......
class "CL2" ......
class "CL4" ......
Search for a class not already declared (expample "CL3", of lowest
number - 3)
and print a new class with a value of a variable (example var)
class "CL1" ......
class "CL2" ......
class "CL3" ......xyz $var
class "CL4" ......
The file should thus be edited and this new class added to it, with the
right position
in the file.
Any ideas, I would appreciate any help...
Sahil
| |
| Ed Morton 2006-11-30, 7:23 pm |
| sahilbahri@gmail.com wrote:
> Hi,
>
> I need to open a text file with classes declared as:
>
> class "CL1" ......
> class "CL2" ......
> class "CL4" ......
>
> Search for a class not already declared (expample "CL3", of lowest
> number - 3)
> and print a new class with a value of a variable (example var)
>
> class "CL1" ......
> class "CL2" ......
> class "CL3" ......xyz $var
> class "CL4" ......
>
> The file should thus be edited and this new class added to it, with the
> right position
> in the file.
>
> Any ideas, I would appreciate any help...
>
> Sahil
>
It's not really clear what you mean by "print a new class with a value
of a variable (example var)" and "xyz $var" but something like this
(untested) might get you close:
awk '{
thisnr = $2
gsub(/[^0-9]/,"",thisnr)
while (thisnr != prevnr+1) {
sub(thisnr,++thisnr)
print # add $0, "xyz $var" if thats what you want
}
prevnr = thisnr
}' file
Regards,
Ed.
|
|
|
|
|