- 论坛徽章:
- 2
|
回复 12# bblxl2012 - sed -rn '
- h; # store 1st line to hold space
- :a; # set label "a"
- n; # read the next line
- /^\|/H; # if the line starts with '|', append the current line to hold space
- /^[^|]/{x;bb}; # if line starts without '|' or reading last line (the next command line), do command "x" to exchange the context in hold space and pattern space, then branch to label "b";
- ${x;bb};
- ba; # branch to label "a"
- :b; # set label "b";
- s/([^|]+\|([^|]+)\|[^\n]+)(.*)\n\|\2(\|.*)/\1\3\n|\4/; # treat the context in the pattern space by s/// to fit your aim
- tb; # if s/// has done successfully, branch to label "b"; otherwise, execute the next command line;
- p; # print the context in the pattern space
- ba # branch to label "a"
- '
复制代码 |
|