Saturday 15 August 2015

linux - I am having trouble with Sed -



linux - I am having trouble with Sed -

i trying utilize sed command replace line:

charmm.c36a4.20140107.newcali4.fixhcali.grange.b

with:

charmm.20140911.c36a4.3rd.ghost2.model3rd

when use:

sed -i '/s/firstline/secondline/g'

it doesn't work. think periods messing up. how around this?

sed uses regular expressions, . matches character. if want match . character itself, tell sed \.

so alter first line sec line:

sed -e 's/charmm\.c36a4.20140107\.newcali4\.fixhcali\.grange\.b/charmm.20140911.c36a4.3rd.ghost2.model3rd/g' < filetochange >newfile

here, added "g" globally, ie, if there several instances on same line, changed. if remove "g", alter first occurence on each line.

it reads filetochange , writes newfile

if :

sed -i -e 's/charmm\.c36a4.20140107\.newcali4\.fixhcali\.grange\.b/charmm.20140911.c36a4.3rd.ghost2.model3rd/g' filetochange

it straight alter in "filetochange" ... please careful, badly written sed -i mess file , create unusable

linux string replace sed

No comments:

Post a Comment