From BRTT
Examples of dbset using patsub
Occasionally you may have to change the 'dir' field in a wfdisc table, or all of the station names in a site table. This is accomplished by using the dbset command with the 'patsub' command used for pattern matching. I have found a few commands that I use often (more than once?) and share them here. Most involve changing the 'dir' field in the wfdisc table.
- Change XN_0002/* to XW_0002/* for all dfile fields of the wftar table
dbset -v test.wftar tfile '*' 'patsub(tfile, "(XN)", "XW$2")'
- Remove an extra directory from a complicated path in a wfdisc
dbset -cv knet_tmp1998174.wfdisc dir '*' 'patsub(dir,"wf/knet","wf$2")'
dbset: Change 'wf/knet/1998/174' to 'wf/1998/174' at wfdisc.dir#0?
- Change all station names from 1, 2, 3,... to WD1, WD2, WD3,... for
each wfdisc in the current directory.
foreach wf (*.wfdisc)
echo $wf
dbset -v $wf chan '*' 'patsub(chan, "(.*)", "WDO$1") '
end
- Replace start of path in 'dir' field for all records in a wfdisc
dbset -cv check_92.wfdisc dir "'/hf_wo/*'" 'patsub(dir, "/hf_wo/", "wf/$1")'
dbset: Change '/hf_wo/anza/1992/004/190940' to 'wf/anza/1992/004/190940' at wfdisc.dir#0?