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

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1216 | 回復(fù): 5
打印 上一主題 下一主題

求助,急 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2006-03-21 09:27 |只看該作者 |倒序瀏覽
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

論壇徽章:
0
2 [報告]
發(fā)表于 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ù)制代碼

論壇徽章:
0
3 [報告]
發(fā)表于 2006-03-21 12:10 |只看該作者

修改一下,有點錯誤:

  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ù)制代碼

論壇徽章:
0
4 [報告]
發(fā)表于 2006-03-22 02:15 |只看該作者
能不能簡單解釋一下h,D, G 以及最后一行的含義,謝謝

論壇徽章:
1
榮譽會員
日期:2011-11-23 16:44:17
5 [報告]
發(fā)表于 2006-03-22 02:18 |只看該作者
http://www.72891.cn/viewthread.php?tid=336126
BTW:注意論壇發(fā)貼要求

論壇徽章:
0
6 [報告]
發(fā)表于 2006-03-22 08:46 |只看該作者
還是awk簡單一點
NF == 1 { name=$1}
NF > 1 {print name, $1, $NF}

然后再把所有的"/"去掉就行了
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP