| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hello, I'm trying to write a script to edit the gdm.conf file in order to change the Welcome= line. I was trying: if ( $0~/^Welcome/) {print "Welcome=New welcome message"} which works, but I can't quite seem to get the correct syntax to say if there isn't a "^Welcome=" line, add one. Any suggestions? Thanks! Brad |
|
#2
| |||
| |||
| brad.vanorden@gmail.com wrote: > Hello, > > I'm trying to write a script to edit the gdm.conf file in order to > change the Welcome= line. I was trying: > > if ( $0~/^Welcome/) {print "Welcome=New welcome message"} > > which works, but I can't quite seem to get the correct syntax to say > if there isn't a "^Welcome=" line, add one. Any suggestions? > I guess your working code is somewhere from the middle of a rule. A simple solution for adding a line at the end would be: .... if ( $0~/^Welcome/) {print "Welcome=New welcome message" ; seen=1} .... END {if (! seen) print "Welcome=New welcome message"} Hermann |
|
#3
| |||
| |||
| On Aug 11, 2:36 pm, brad.vanor...@gmail.com wrote: > Hello, > > I'm trying to write a script to edit the gdm.conf file in order to > change the Welcome= line. I was trying: > > if ( $0~/^Welcome/) {print "Welcome=New welcome message"} > > which works, but I can't quite seem to get the correct syntax to say > if there isn't a "^Welcome=" line, add one. Any suggestions? > > Thanks! > > Brad Came up with the answer. In the BEGIN section, set a variable to 0. If the pattern matches, change it to 1. In the END section, test if variable is 0. If so, print the new welcome message. Regards, Brad |
|
#4
| |||
| |||
| brad.vanorden@gmail.com wrote: > In the BEGIN section, set a variable to 0. You can just skip this part. Awk does it for you. Hermann |
|
#5
| |||
| |||
| In article <7635edff-946e-4749-9d91-91253030932c@w7g2000hsa.googlegroups.com> , brad.vanorden@gmail.com wrote: > Hello, > > I'm trying to write a script to edit the gdm.conf file in order to > change the Welcome= line. I was trying: > > if ( $0~/^Welcome/) {print "Welcome=New welcome message"} > > which works, but I can't quite seem to get the correct syntax to say > if there isn't a "^Welcome=" line, add one. Any suggestions? > > Thanks! > > Brad awk ' BEGIN { print "Welcome=New welcome message" } ! /^Welcome=/ { print } # print anything expect a welcome ' gdm.conf >new.gdm.conf |
|
#6
| |||
| |||
| On 8/11/2008 1:36 PM, brad.vanorden@gmail.com wrote: > Hello, > > I'm trying to write a script to edit the gdm.conf file in order to > change the Welcome= line. I was trying: > > if ( $0~/^Welcome/) {print "Welcome=New welcome message"} > > which works, but I can't quite seem to get the correct syntax to say > if there isn't a "^Welcome=" line, add one. Any suggestions? > > Thanks! > > Brad awk 'BEGIN{print "Welcome=New welcome message"} /^Welcome/{next}' file Ed. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.