P********e 发帖数: 544 | 1 Sorry, no Chinese input here.
I have a text file containing couple hundreds of the record, such as the
block at the end of this post.
For every line starting with "rs", I need to change the number, "89", to "
159". Similarly, for every line starting
with label, I also need change "89" to "159". the commond
sed 's/G89N/G159N/g'
can change them individually. But the problem is I have more than 300 lines
that needs change, and I have
about 10 such files to work with.
Any better way to finish this? | r****t 发帖数: 10904 | 2 你这个不是在改原始数据吧?
sed 应该类似, 这个是 vim 的做法:
除了第一个冒号,你吧冒号换成 / 也行的。
lines | P********e 发帖数: 544 | 3 Here is perl code for this purpose.
perl -p -i -e 's#(label\s[A-Z])(\d{1,3})([A-Z])#"$1".($2+60)."$3"#ge; s#(rs\
s|[A-Z])(\d{1,3})(|[A-Z]|\s|[A-
Z])(\d{1,3})(|[A-Z]|)#"$1".($2+60)."$3".($4+60)."$5"#ge' file_name_goes_here
.dat
BTW: this is not raw data.
【在 r****t 的大作中提到】 : 你这个不是在改原始数据吧? : sed 应该类似, 这个是 vim 的做法: : 除了第一个冒号,你吧冒号换成 / 也行的。 : lines
| c*m 发帖数: 1114 | 4 这个哪里有这么复杂,
假设是以rs开头的行吧89换成159可以用
sed '/^rs/s/89/159/g'
其他依次类推。好久不用sed,具体用法记不清了,自己查查sed的男人页。
rs\
here
【在 P********e 的大作中提到】 : Here is perl code for this purpose. : perl -p -i -e 's#(label\s[A-Z])(\d{1,3})([A-Z])#"$1".($2+60)."$3"#ge; s#(rs\ : s|[A-Z])(\d{1,3})(|[A-Z]|\s|[A- : Z])(\d{1,3})(|[A-Z]|)#"$1".($2+60)."$3".($4+60)."$5"#ge' file_name_goes_here : .dat : BTW: this is not raw data.
| P********e 发帖数: 544 | 5 I have more than 360 lines to change for all 10 files.
【在 c*m 的大作中提到】 : 这个哪里有这么复杂, : 假设是以rs开头的行吧89换成159可以用 : sed '/^rs/s/89/159/g' : 其他依次类推。好久不用sed,具体用法记不清了,自己查查sed的男人页。 : : rs\ : here
| E*U 发帖数: 2028 | 6 man, did you ever try "sed"?
it works line by line
which means it works for every line
【在 P********e 的大作中提到】 : I have more than 360 lines to change for all 10 files.
| P********e 发帖数: 544 | 7 Unless sed can automatically run through 89, 90, 91, 92 ...... 399.
【在 E*U 的大作中提到】 : man, did you ever try "sed"? : it works line by line : which means it works for every line
|
|