亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 求助,急 [打印本頁]

作者: qzhu    時(shí)間: 2006-03-21 09:27
標(biāo)題: 求助,急
Hi,

I need to parse a file to a new format:

source file format is like this:
/ABC
abc 0 0 0 0 0 1
efg 0 0 0 0 0  3

/XYZ
cde 0 0 0 0 0 1
fgh 0 0 0 0 0  1
uvw 0 0 0 0 0 2

......

need to parse it to a new file like this:
ABC abc  1
ABC efg  3
XYZ cde  1
XYZ fgh   1
XYZ uvw  2
...

basically what need to be done is to get the name after the slash "/" and  combine it with the first and last column of lines immediately after it.
I know a little bit of awk and sed but not enough to solve this problem, any help or hint with a piece of code will be appreciated.

Thanks,
Qing
作者: dbcat    時(shí)間: 2006-03-21 09:58

  1. sed '
  2. s/ 0//g
  3. /\//h
  4. s/^\/.*//
  5. /\//!{
  6. G
  7. s/\n//
  8. s/^\/.*//
  9. s/\(.*\)\/\(.*\)/\2 \1/
  10. }
  11. ' file
復(fù)制代碼

作者: dbcat    時(shí)間: 2006-03-21 12:10

修改一下,有點(diǎn)錯(cuò)誤:

  1. sed '
  2. /^$/d
  3. /^\//{
  4. h
  5. D
  6. }
  7. {
  8. G
  9. s/\n//
  10. s/\([^ ]*\)\(.*\)\(.\)\/\(.*\)/\4 \1 \3/
  11. }
  12. ' file
復(fù)制代碼

作者: qzhu    時(shí)間: 2006-03-22 02:15
能不能簡單解釋一下h,D, G 以及最后一行的含義,謝謝
作者: 寂寞烈火    時(shí)間: 2006-03-22 02:18
http://www.72891.cn/viewthread.php?tid=336126
BTW:注意論壇發(fā)貼要求
作者: qzhu    時(shí)間: 2006-03-22 08:46
還是awk簡單一點(diǎn)
NF == 1 { name=$1}
NF > 1 {print name, $1, $NF}

然后再把所有的"/"去掉就行了




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2