Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cutting out chunks of a file based on variables 1

Status
Not open for further replies.
Apr 6, 2001
1,052
CA
I am trying to automate the removal of some chunks of a smb.conf file using awk. I need it to match on some constant text combined with an environment variable. what i have so far:

awk -v pattern="text"$ENVVAR 'BEGIN { RS = "[" }
!/^pattern/ { print "["$0 }' ./smb.conf

i think my problem is the ^ combined with the variable, if i just use hard coded text it works fine.

???
 
I don't think variables are recognised between the // regexp delimiters.

Try this:

[tt]awk -v pattern="^text"$ENVVAR 'BEGIN { RS = ORS = "[" }
$0 !~ pattern { print }' ./smb.conf[/tt]

Annihilannic.
 
Sorry, I'll just tidy that up a little:

[tt]awk -v pattern="^text"$ENVVAR '
BEGIN { RS = ORS = "[" }
$0 !~ pattern
' ./smb.conf[/tt]

Annihilannic.
 
Thanks Anni

worked like a charm.
only problem is an extra [ at the end of the file, but that should be easy enough to clean up
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top