我有以下文件:
cat file1.m
(4 (5 y^7 (-1 + 4 z) + y^6 (15 - 83 z + 80 z^2) -
5 z^4 (-2 + 4 z - 3 z^2 + z^3) + y^5 (-20 + 147 z - 273 z^2 + 140 z^3) +
y z^3 (40 - 154 z + 147 z^2 - 83 z^3 + 20 z^4) +
y^2 z^2 (60 - 254 z + 363 z^2 - 273 z^3 + 80 z^4) +
y^3 z (40 - 254 z + 462 z^2 - 439 z^3 + 140 z^4) +
y^4 (10 - 154 z + 363 z^2 - 439 z^3 + 160 z^4)) -
9 (y + z)^4 (2 + y^2 (3 - 9 z) - 4 z + 3 z^2 - z^3 + y^3 (-1 + 4 z) +
y (-4 + 12 z - 9 z^2 + 4 z^3)) H(0, y) -
9 (y + z)^4 (2 + y^2 (3 - 9 z) - 4 z + 3 z^2 - z^3 + y^3 (-1 + 4 z) +
y (-4 + 12 z - 9 z^2 + 4 z^3)) H(0, z) +
36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2) +
z^2 (6 - 5 z + 3 z^2)) H(1, z) +
36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2) +
z^2 (6 - 5 z + 3 z^2)) H(2, y))/(216 y z (-1 + y + z) (y + z)^4)
我想重写这个文件,以便删除所有前导空格,并且我想在某些列(比如第80列)之后强行打破该行。 到目前为止,第一个问题是使用
解决的sed -e 's/^[ \t]*//' file1.m > file2.m
但是如何在一些专栏之后突破界限呢? 所需的输出是
(4 (5 y^7 (-1 + 4 z) + y^6 (15 - 83 z + 80 z^2) - 5 z^4 (-2 + 4 z - 3 z^2 + z^3)
+ y^5 (-20 + 147 z - 273 z^2 + 140 z^3) + y z^3 (40 - 154 z + 147 z^2 - 83 z^3
+ 20 z^4) + y^2 z^2 (60 - 254 z + 363 z^2 - 273 z^3 + 80 z^4) + y^3 z (40
- 254 z + 462 z^2 - 439 z^3 + 140 z^4) + y^4 (10 - 154 z + 363 z^2 - 439 z^3
+ 160 z^4)) - 9 (y + z)^4 (2 + y^2 (3 - 9 z) - 4 z + 3 z^2 - z^3 + y^3 (-1
+ 4 z) + y (-4 + 12 z - 9 z^2 + 4 z^3)) H(0, y) - 9 (y + z)^4 (2 + y^2 (3 - 9 z)
- 4 z + 3 z^2 - z^3 + y^3 (-1 + 4 z) + y (-4 + 12 z - 9 z^2 + 4 z^3)) H(0, z)
+ 36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2) + z^2 (6 - 5 z + 3 z^2))
H(1, z) + 36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2) + z^2 (6 - 5 z
+ 3 z^2)) H(2, y))/(216 y z (-1 + y + z) (y + z)^4)
答案 0 :(得分:4)
您可以结合使用Pygame documentation on drawing和tr:
$ sed 's/^[ \t]*//' a.m | tr -d '\n' | fold -w80
(4 (5 y^7 (-1 + 4 z) + y^6 (15 - 83 z + 80 z^2) -5 z^4 (-2 + 4 z - 3 z^2 + z^3)
+ y^5 (-20 + 147 z - 273 z^2 + 140 z^3) +y z^3 (40 - 154 z + 147 z^2 - 83 z^3 +
20 z^4) +y^2 z^2 (60 - 254 z + 363 z^2 - 273 z^3 + 80 z^4) +y^3 z (40 - 254 z +
462 z^2 - 439 z^3 + 140 z^4) +y^4 (10 - 154 z + 363 z^2 - 439 z^3 + 160 z^4)) -9
(y + z)^4 (2 + y^2 (3 - 9 z) - 4 z + 3 z^2 - z^3 + y^3 (-1 + 4 z) +y (-4 + 12 z
- 9 z^2 + 4 z^3)) H(0, y) -9 (y + z)^4 (2 + y^2 (3 - 9 z) - 4 z + 3 z^2 - z^3 +
y^3 (-1 + 4 z) +y (-4 + 12 z - 9 z^2 + 4 z^3)) H(0, z) +36 y z (-5 y^3 + 3 y^4
+ y z^2 + y^2 (6 + z - 6 z^2) +z^2 (6 - 5 z + 3 z^2)) H(1, z) +36 y z (-5 y^3 +
3 y^4 + y z^2 + y^2 (6 + z - 6 z^2) +z^2 (6 - 5 z + 3 z^2)) H(2, y))/(216 y z (-
1 + y + z) (y + z)^4)
答案 1 :(得分:1)
您可以使用sed
制作自己的折叠规则。
以下是如何将+或 - 作为行的第一个字符。
sed -e 's/^[ \t]*//' file1.m |
tr -d '\n' |
sed 's/\(\(.\)\{,80\}\) \([\+\-]\)/\1\n\3/g'
编辑:
没有格式化反斜杠就消失了。我还删除了\{70,80\}
中70的下限。
结果:
(4 (5 y^7 (-1 + 4 z) + y^6 (15 - 83 z + 80 z^2) - 5 z^4 (-2 + 4 z - 3 z^2
+ z^3)+ y^5 (-20 + 147 z - 273 z^2 + 140 z^3) + y z^3 (40 - 154 z + 147 z^2
- 83 z^3+ 20 z^4) + y^2 z^2 (60 - 254 z + 363 z^2 - 273 z^3 + 80 z^4)
+ y^3 z (40- 254 z + 462 z^2 - 439 z^3 + 140 z^4) + y^4 (10 - 154 z + 363 z^2
- 439 z^3+ 160 z^4)) - 9 (y + z)^4 (2 + y^2 (3 - 9 z) - 4 z + 3 z^2 - z^3
+ y^3 (-1+ 4 z) + y (-4 + 12 z - 9 z^2 + 4 z^3)) H(0, y) - 9 (y + z)^4 (2
+ y^2 (3 - 9 z)- 4 z + 3 z^2 - z^3 + y^3 (-1 + 4 z) + y (-4 + 12 z - 9 z^2
+ 4 z^3)) H(0, z)+ 36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2) + z^2 (6
- 5 z + 3 z^2))H(1, z) + 36 y z (-5 y^3 + 3 y^4 + y z^2 + y^2 (6 + z - 6 z^2)
+ z^2 (6 - 5 z+ 3 z^2)) H(2, y))/(216 y z (-1 + y + z) (y
+ z)^4)