我试图在目录中使用sed进行批量更改,从{{ form|as_bootstrap }}
到{% bootstrap_form form %}
,但是"表单"可以是任何名称,例如" process_form"或" user_form"。
我找到了一个列出所有这些内容的grep:grep -r '{{ [a-z_\.]*^\|as_bootstrap }}' ./
所以我尝试使用这个grep / sed命令,但它不起作用:
grep -rl '{{ [a-z_\.]*^\|as_bootstrap }}' ./ | xargs sed -Ei s@'{{ \([a-z_\.]*\)^\|as_bootstrap }}'@'{% bootstrap_form \1 %}'@g
你能指出我在sed regexp中的错误吗?
答案 0 :(得分:2)
您必须以sed扩展模式(}
)转义-E
和sed 's/{{ \([^|]*\)|as_bootstrap }}/{% bootstrap_form \1 %}/'
。但您也可以使用BRE模式来避免转义卷曲的问题:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:XE"></property>
<property name="username" value="SYSTEM"></property>
<property name="password" value="admin"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="datasource" ref="datasource"></property>
<property name="annotatedClasses">
<list>
<value>spring.SpringORM.Student</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.oracl11gDialect</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="studnetDaoImplement" class="spring.SpringORM.StudnetDaoImplement">
<constructor-arg ref="hibernateTemplate" />
</bean>
</beans>