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

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
12下一頁(yè)
最近訪問(wèn)板塊 發(fā)新帖
查看: 3002 | 回復(fù): 12
打印 上一主題 下一主題

[文本處理] 如何對(duì)不同列的文本進(jìn)行分別處理 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-07-31 11:54 |只看該作者 |倒序?yàn)g覽
對(duì)不起,本人的shell水平還是有點(diǎn)菜
如下:
[23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
[23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
[23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
[23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
[23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
[23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
我想分別截掉第一列的[符號(hào),第二列的/install?
只保留23/Jul/2014:18:14:29  os=4.1.1&clickid
并將第一列處理成時(shí)間戳的形式
請(qǐng)問(wèn)怎么做,謝謝!

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2014-07-31 12:08 |只看該作者
  1. sed 's/\[//;s#/install?##' file
復(fù)制代碼
時(shí)間戳是什么格式?求解。

論壇徽章:
1
處女座
日期:2014-09-18 16:18:00
3 [報(bào)告]
發(fā)表于 2014-07-31 12:13 |只看該作者
  1. awk '{sub(/\[/,"",$1);sub(/\/install\?/,"",$2)}1' testfile
復(fù)制代碼
同樣想知道,時(shí)間戳是具體什么格式,純數(shù)字字符串?

論壇徽章:
145
技術(shù)圖書徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11獅子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龍
日期:2014-01-08 15:26:12技術(shù)圖書徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
4 [報(bào)告]
發(fā)表于 2014-07-31 12:35 |只看該作者
回復(fù) 1# hao3721

would you like this ...

$ awk '{gsub(/[[/]/," ",$1);sub(/:/," ",$1);gsub(/\/install\?/,"",$2);cmd="date -d \""$1"\" +%s";cmd |& getline s;print s,$2}' FILE
1406110469 os=4.1.1&clickid
1406110469 os=4.1.1&clickid
1406110469 os=4.1.1&clickid
1406110469 os=4.1.1&clickid
1406110469 os=4.1.1&clickid
1406110469 os=4.1.1&clickid


   

論壇徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16賽季CBA聯(lián)賽之北京
日期:2016-07-06 15:42:0715-16賽季CBA聯(lián)賽之同曦
日期:2016-06-12 10:38:0915-16賽季CBA聯(lián)賽之佛山
日期:2016-05-27 11:54:56黃金圣斗士
日期:2015-12-02 11:44:35白銀圣斗士
日期:2015-11-25 14:32:43白銀圣斗士
日期:2015-11-23 12:53:352015亞冠之布里斯班獅吼
日期:2015-10-21 16:55:482015亞冠之首爾
日期:2015-09-01 16:46:052015亞冠之德黑蘭石油
日期:2015-08-31 11:39:192015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-08-28 21:06:5315-16賽季CBA聯(lián)賽之廣東
日期:2016-07-12 14:58:53
5 [報(bào)告]
發(fā)表于 2014-07-31 13:40 |只看該作者
回復(fù) 4# jason680


少了個(gè)close(cmd) ,否則后面的時(shí)間戳數(shù)據(jù)都不正常了! 另外,我想知道, cmd |& getline ,這里的 & 有什么作用?
  1. [root@localhost ~]#
  2. [root@localhost ~]# awk '{gsub(/[[/]/," ",$1);sub(/:/," ",$1);gsub(/\/install\?/,"",$2);cmd="date -d \""$1"\" +%s";cmd | getline s;print s,$2;close(cmd)}' /tmp/file
  3. 1406110469 os=4.1.1&clickid
  4. 1406110479 os=4.1.1&clickid
  5. 1406110489 os=4.1.1&clickid
  6. 1406110499 os=4.1.1&clickid
  7. 1406110529 os=4.1.1&clickid
  8. 1406110539 os=4.1.1&clickid
  9. 1406110469 os=4.1.1&clickid
  10. 1406110469 os=4.1.1&clickid
  11. [root@localhost ~]# awk '{gsub(/[[/]/," ",$1);sub(/:/," ",$1);gsub(/\/install\?/,"",$2);cmd="date -d \""$1"\" +%s";cmd | getline s;print s,$2;}' /tmp/file         
  12. 1406110469 os=4.1.1&clickid
  13. 1406110479 os=4.1.1&clickid
  14. 1406110489 os=4.1.1&clickid
  15. 1406110499 os=4.1.1&clickid
  16. 1406110529 os=4.1.1&clickid
  17. 1406110539 os=4.1.1&clickid
  18. 1406110539 os=4.1.1&clickid
  19. 1406110539 os=4.1.1&clickid
  20. [root@localhost ~]# cat /tmp/file
  21. [23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
  22. [23/Jul/2014:18:14:39        /install?os=4.1.1&clickid
  23. [23/Jul/2014:18:14:49        /install?os=4.1.1&clickid
  24. [23/Jul/2014:18:14:59        /install?os=4.1.1&clickid
  25. [23/Jul/2014:18:15:29        /install?os=4.1.1&clickid
  26. [23/Jul/2014:18:15:39        /install?os=4.1.1&clickid
  27. [23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
  28. [23/Jul/2014:18:14:29        /install?os=4.1.1&clickid
  29. [root@localhost ~]#



復(fù)制代碼

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-02 06:20:00IT運(yùn)維版塊每月發(fā)帖之星
日期:2015-09-11 19:30:52IT運(yùn)維版塊每周發(fā)帖之星
日期:2015-09-11 19:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-26 06:20:00每日論壇發(fā)貼之星
日期:2015-08-20 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-20 06:20:002015年辭舊歲徽章
日期:2015-03-03 16:54:15金牛座
日期:2014-05-04 16:58:09雙子座
日期:2013-12-17 16:44:37辰龍
日期:2013-11-22 15:20:59獅子座
日期:2013-11-18 22:55:08射手座
日期:2013-11-12 10:54:26
6 [報(bào)告]
發(fā)表于 2014-07-31 13:48 |只看該作者
本帖最后由 wenhq 于 2014-07-31 13:49 編輯

[root@1 ~]# perl -p -lne 'print if s/\[// && s#/install\?##'  test
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid
23/Jul/2014:18:14:29        os=4.1.1&clickid

論壇徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16賽季CBA聯(lián)賽之北京
日期:2016-07-06 15:42:0715-16賽季CBA聯(lián)賽之同曦
日期:2016-06-12 10:38:0915-16賽季CBA聯(lián)賽之佛山
日期:2016-05-27 11:54:56黃金圣斗士
日期:2015-12-02 11:44:35白銀圣斗士
日期:2015-11-25 14:32:43白銀圣斗士
日期:2015-11-23 12:53:352015亞冠之布里斯班獅吼
日期:2015-10-21 16:55:482015亞冠之首爾
日期:2015-09-01 16:46:052015亞冠之德黑蘭石油
日期:2015-08-31 11:39:192015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-08-28 21:06:5315-16賽季CBA聯(lián)賽之廣東
日期:2016-07-12 14:58:53
7 [報(bào)告]
發(fā)表于 2014-07-31 13:48 |只看該作者
回復(fù) 4# jason680
  1.        command | getline [var]
  2.                              Run command piping the output either into $0 or var, as above.

  3.        command |& getline [var]
  4.                              Run command as a co-process piping the output either into $0 or var, as above.  Co-processes are a gawk extension.
復(fù)制代碼
這兩個(gè)有何本質(zhì)區(qū)別呀? .

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-02 06:20:00IT運(yùn)維版塊每月發(fā)帖之星
日期:2015-09-11 19:30:52IT運(yùn)維版塊每周發(fā)帖之星
日期:2015-09-11 19:20:31IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-26 06:20:00每日論壇發(fā)貼之星
日期:2015-08-20 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-20 06:20:002015年辭舊歲徽章
日期:2015-03-03 16:54:15金牛座
日期:2014-05-04 16:58:09雙子座
日期:2013-12-17 16:44:37辰龍
日期:2013-11-22 15:20:59獅子座
日期:2013-11-18 22:55:08射手座
日期:2013-11-12 10:54:26
8 [報(bào)告]
發(fā)表于 2014-07-31 13:50 |只看該作者
回復(fù) 7# reyleon


     co-process ?

論壇徽章:
60
20周年集字徽章-20	
日期:2020-10-28 14:04:3015-16賽季CBA聯(lián)賽之北京
日期:2016-07-06 15:42:0715-16賽季CBA聯(lián)賽之同曦
日期:2016-06-12 10:38:0915-16賽季CBA聯(lián)賽之佛山
日期:2016-05-27 11:54:56黃金圣斗士
日期:2015-12-02 11:44:35白銀圣斗士
日期:2015-11-25 14:32:43白銀圣斗士
日期:2015-11-23 12:53:352015亞冠之布里斯班獅吼
日期:2015-10-21 16:55:482015亞冠之首爾
日期:2015-09-01 16:46:052015亞冠之德黑蘭石油
日期:2015-08-31 11:39:192015亞冠之薩濟(jì)拖拉機(jī)
日期:2015-08-28 21:06:5315-16賽季CBA聯(lián)賽之廣東
日期:2016-07-12 14:58:53
9 [報(bào)告]
發(fā)表于 2014-07-31 13:53 |只看該作者
回復(fù) 8# wenhq


    字面上是協(xié)同進(jìn)程的意思! 可惜不懂呀..   看來(lái)需要惡補(bǔ)呀.

論壇徽章:
145
技術(shù)圖書徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11獅子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龍
日期:2014-01-08 15:26:12技術(shù)圖書徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
10 [報(bào)告]
發(fā)表于 2014-07-31 13:58 |只看該作者
回復(fù) 5# reyleon

1. thank you for your information with close(cmd)

2. getline please refer manual ...
Note: I think using "|" can do it well in this case

http://www.gnu.org/software/gawk/manual/gawk.html#Getline_002fCoprocess

4.9.10 Summary of getline Variants

Table 4.1 summarizes the eight variants of getline, listing which built-in variables are set by each one, and whether the variant is standard or a gawk extension. Note: for each variant, gawk sets the RT built-in variable.
Variant        Effect        Standard / Extension
getline        Sets $0, NF, FNR, NR, and RT        Standard
getline var        Sets var, FNR, NR, and RT        Standard
getline < file        Sets $0, NF, and RT        Standard
getline var < file        Sets var and RT        Standard
command | getline        Sets $0, NF, and RT        Standard
command | getline var        Sets var and RT        Standard
command |& getline        Sets $0, NF, and RT        Extension
command |& getline var        Sets var and RT        Extension

...

4.9.7 Using getline from a Coprocess

Input into getline from a pipe is a one-way operation. The command that is started with ‘command | getline’ only sends data to your awk program.

On occasion, you might want to send data to another program for processing and then read the results back. gawk allows you to start a coprocess, with which two-way communications are possible. This is done with the ‘|&’ operator. Typically, you write data to the coprocess first and then read results back, as shown in the following:

print "some query" |& "db_server"
"db_server" |& getline


which sends a query to db_server and then reads the results.

The values of NR and FNR are not changed, because the main input stream is not used. However, the record is split into fields in the normal manner, thus changing the values of $0, of the other fields, and of NF and RT.

Coprocesses are an advanced feature. They are discussed here only because this is the section on getline. See Two-way I/O, where coprocesses are discussed in more detail.

...
4.9.8 Using getline into a Variable from a Coprocess

When you use ‘command |& getline var’, the output from the coprocess command is sent through a two-way pipe to getline and into the variable var.

In this version of getline, none of the built-in variables are changed and the record is not split into fields. The only variable changed is var. However, RT is set.     
您需要登錄后才可以回帖 登錄 | 注冊(cè)

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP