免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 3390 | 回复: 15
打印 上一主题 下一主题

一个变量赋值的问题(未解决) [复制链接]

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:48:31
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-08 15:11 |只看该作者 |倒序浏览
一个变量赋值的问题:
txt文件内容:
----------------------------------
E1
A:111
B:33333
C:---
44444

E2
A:211
B:443333
C:---
4454

E3
A:231
B:55333
C:---
11114
----------------------------------

怎么样赋值得到这样的数据:
id:E1
A:111
B:33333
C:44444

id:E2
A:211
B:443333
C:4454

id:E3
A:231
B:55333
C:11114

怎么样做这个?

论坛徽章:
1
处女座
日期:2014-12-23 17:59:27
2 [报告]
发表于 2008-10-08 15:24 |只看该作者
awk 'BEGIN{RS="";FS="\n";OFS="\n"}{$1="id:"$1;print $0"\n"}'  urfile

论坛徽章:
71
15-16赛季CBA联赛之同曦
日期:2018-08-23 15:41:42辰龙
日期:2014-08-15 09:07:43狮子座
日期:2014-06-03 13:55:33亥猪
日期:2014-06-02 11:17:08巨蟹座
日期:2014-05-06 10:02:03午马
日期:2014-05-04 08:18:27亥猪
日期:2014-04-29 11:11:32技术图书徽章
日期:2014-04-24 15:51:26技术图书徽章
日期:2014-04-17 11:01:53辰龙
日期:2014-04-15 12:45:46亥猪
日期:2014-04-11 09:06:23射手座
日期:2014-04-01 15:28:10
3 [报告]
发表于 2008-10-08 15:34 |只看该作者
修改2楼:
awk 'BEGIN{RS="";FS="\n";OFS="\n"}{$1="id:"$1;$4="C:"$5;$5="";print $1"\n"$2"\n"$3"\n"$4"\n"}' file

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
4 [报告]
发表于 2008-10-08 15:38 |只看该作者
原帖由 zhaopingzi 于 2008-10-8 15:34 发表
修改2楼:
awk 'BEGIN{RS="";FS="\n";OFS="\n"}{$1="id:"$1;$4="C:"$5;$5="";print $1"\n"$2"\n"$3"\n"$4"\n"}' file


修改3楼:
awk 'BEGIN{RS="";FS=OFS="\n"}{$1="id:"$1;$4="C:"$5;NF--;print $0"\n"}' file

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:48:31
5 [报告]
发表于 2008-10-08 15:41 |只看该作者
如果是这样呢?
----------------------------------
E1 fdfd sfds
A:111
B:33333
C:---
44444

E2 rr fdsfsdf
A:211
B:443333
C:---
4454

E3 dfdsf fdfsd
A:231
B:55333
C:---
11114
----------------------------------
能不能分块进行赋值

论坛徽章:
1
处女座
日期:2014-12-23 17:59:27
6 [报告]
发表于 2008-10-08 15:41 |只看该作者


faint.
没看清题,谢谢 两位。

论坛徽章:
1
处女座
日期:2014-12-23 17:59:27
7 [报告]
发表于 2008-10-08 15:45 |只看该作者
原帖由 stokeorange 于 2008-10-8 15:41 发表
如果是这样呢?
----------------------------------
E1 fdfd sfds
A:111
B:33333
C:---
44444

E2 rr fdsfsdf
A:211
B:443333
C:---
4454

E3 dfdsf fdfsd
A:231
B:55333
C:---
11114
- ...


awk 'BEGIN{RS="";FS=OFS="\n"}{$1="id:"substr($1,0,2);$4="C:"$5;NF--;print $0"\n"}'

论坛徽章:
71
15-16赛季CBA联赛之同曦
日期:2018-08-23 15:41:42辰龙
日期:2014-08-15 09:07:43狮子座
日期:2014-06-03 13:55:33亥猪
日期:2014-06-02 11:17:08巨蟹座
日期:2014-05-06 10:02:03午马
日期:2014-05-04 08:18:27亥猪
日期:2014-04-29 11:11:32技术图书徽章
日期:2014-04-24 15:51:26技术图书徽章
日期:2014-04-17 11:01:53辰龙
日期:2014-04-15 12:45:46亥猪
日期:2014-04-11 09:06:23射手座
日期:2014-04-01 15:28:10
8 [报告]
发表于 2008-10-08 15:46 |只看该作者
awk 'BEGIN{RS="";FS="\n";OFS="\n"}{$1="id:"$1;$4="C:"$5;$5="";print $0}' file

论坛徽章:
0
9 [报告]
发表于 2008-10-08 15:57 |只看该作者
好久没用sed了,来温习一下……
sed 's/.*/id:&/;N;N;N;N;N;s/-\{1,\}\n//'

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:48:31
10 [报告]
发表于 2008-10-08 16:10 |只看该作者
last
其实真实文件类似这样:
Ethernet0/1 current state : DOWN
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 000f-e21a-317f
The Maximum Transmit Unit is 1500
Media type is twisted pair, loopback not set
Port hardware type is 100_BASE_TX
Unknown-speed mode, unknown-duplex mode
Link speed type is autonegotiation, link duplex type is autonegotiation
Flow-control is not enabled
Port-flow-constrain has not been configured completely
The Maximum Frame Length is 1536
Broadcast MAX-ratio: 100%
PVID: 101
Mdi type: auto
Port link-type: access
  Tagged   VLAN ID : none
  Untagged VLAN ID : 101
Last 300 seconds input:  0 packets/sec 0 bytes/sec
Last 300 seconds output:  0 packets/sec 0 bytes/sec
Input(total):  196171 packets, 24648090 bytes
         3685 broadcasts, 166 multicasts
Input(normal):  - packets, - bytes
         - broadcasts, - multicasts
Input:  16 input errors, 0 runts, 0 giants,  - throttles, 0 CRC
         0 frame,  - overruns, 16 aborts, 0 ignored, - parity errors
Output(total): 280675 packets, 292064772 bytes
         12333 broadcasts, 2906 multicasts, 0 pauses
Output(normal): - packets, - bytes
         - broadcasts, - multicasts, - pauses
Output: 14 output errors,  - underruns, - buffer failures
         0 aborts, 0 deferred, 0 collisions, 0 late collisions
         14 lost carrier, - no carrier

Ethernet0/2 current state : UP
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 000f-e21a-317f
The Maximum Transmit Unit is 1500
Media type is twisted pair, loopback not set
Port hardware type is 100_BASE_TX
Unknown-speed mode, unknown-duplex mode
Link speed type is autonegotiation, link duplex type is autonegotiation
Flow-control is not enabled
Port-flow-constrain has not been configured completely
The Maximum Frame Length is 1536
Broadcast MAX-ratio: 100%
PVID: 101
Mdi type: auto
Port link-type: access
  Tagged   VLAN ID : none
  Untagged VLAN ID : 101
Last 300 seconds input:  0 packets/sec 0 bytes/sec
Last 300 seconds output:  0 packets/sec 0 bytes/sec
Input(total):  196171 packets, 24648090 bytes
         3685 broadcasts, 166 multicasts
Input(normal):  - packets, - bytes
         - broadcasts, - multicasts
Input:  16 input errors, 0 runts, 0 giants,  - throttles, 0 CRC
         0 frame,  - overruns, 16 aborts, 0 ignored, - parity errors
Output(total): 280675 packets, 292064772 bytes
         12333 broadcasts, 2906 multicasts, 0 pauses
Output(normal): - packets, - bytes
         - broadcasts, - multicasts, - pauses
Output: 14 output errors,  - underruns, - buffer failures
         0 aborts, 0 deferred, 0 collisions, 0 late collisions
         14 lost carrier, - no carrier
                 
Ethernet0/3 current state : DOWN
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 000f-e21a-317f
The Maximum Transmit Unit is 1500
Media type is twisted pair, loopback not set
Port hardware type is 100_BASE_TX
Unknown-speed mode, unknown-duplex mode
Link speed type is autonegotiation, link duplex type is autonegotiation
Flow-control is not enabled
Port-flow-constrain has not been configured completely
The Maximum Frame Length is 1536
Broadcast MAX-ratio: 100%
PVID: 101
Mdi type: auto
Port link-type: access
  Tagged   VLAN ID : none
  Untagged VLAN ID : 101
Last 300 seconds input:  0 packets/sec 0 bytes/sec
Last 300 seconds output:  0 packets/sec 0 bytes/sec
Input(total):  196171 packets, 24648090 bytes
         3685 broadcasts, 166 multicasts
Input(normal):  - packets, - bytes
         - broadcasts, - multicasts
Input:  16 input errors, 0 runts, 0 giants,  - throttles, 0 CRC
         0 frame,  - overruns, 16 aborts, 0 ignored, - parity errors
Output(total): 280675 packets, 292064772 bytes
         12333 broadcasts, 2906 multicasts, 0 pauses
Output(normal): - packets, - bytes
         - broadcasts, - multicasts, - pauses
Output: 14 output errors,  - underruns, - buffer failures
         0 aborts, 0 deferred, 0 collisions, 0 late collisions
         14 lost carrier, - no carrier
                 
Ethernet0/1 current state : DOWN
IP Sending Frames' Format is PKTFMT_ETHNT_2, Hardware address is 000f-e21a-317f
The Maximum Transmit Unit is 1500
Media type is twisted pair, loopback not set
Port hardware type is 100_BASE_TX
Unknown-speed mode, unknown-duplex mode
Link speed type is autonegotiation, link duplex type is autonegotiation
Flow-control is not enabled
Port-flow-constrain has not been configured completely
The Maximum Frame Length is 1536
Broadcast MAX-ratio: 100%
PVID: 101
Mdi type: auto
Port link-type: access
  Tagged   VLAN ID : none
  Untagged VLAN ID : 101
Last 300 seconds input:  0 packets/sec 0 bytes/sec
Last 300 seconds output:  0 packets/sec 0 bytes/sec
Input(total):  196171 packets, 24648090 bytes
         3685 broadcasts, 166 multicasts
Input(normal):  - packets, - bytes
         - broadcasts, - multicasts
Input:  16 input errors, 0 runts, 0 giants,  - throttles, 0 CRC
         0 frame,  - overruns, 16 aborts, 0 ignored, - parity errors
Output(total): 280675 packets, 292064772 bytes
         12333 broadcasts, 2906 multicasts, 0 pauses
Output(normal): - packets, - bytes
         - broadcasts, - multicasts, - pauses
Output: 14 output errors,  - underruns, - buffer failures
         0 aborts, 0 deferred, 0 collisions, 0 late collisions
         14 lost carrier, - no carrier

现在需要出的结果是:
id:Ethernet0/1
stateOWN
type:100_BASE_TX
Input(total):196171 packets

以此类推
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP