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

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

Chinaunix

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

[文本處理] shell重定向問(wèn)題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-03-28 15:02 |只看該作者 |倒序?yàn)g覽

  1. str1='1 2 3 4'
  2. str2='2 4'

  3. echo $(comm -23 <(echo $str1 |xargs -n1|sort) <(echo $str2 |xargs -n1|sort))
復(fù)制代碼
當(dāng)使用#!/bin/bash的時(shí)候沒(méi)有問(wèn)題 但是#!/bin/sh的時(shí)候就會(huì)報(bào)錯(cuò)

syntax error near unexpected token `('

難道上面的那種寫(xiě)法不符合postfix規(guī)范嗎? 如果在#!/bin/sh 該如何寫(xiě)?

論壇徽章:
93
2015年辭舊歲徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年紀(jì)念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大;照
日期:2019-10-10 10:55:38季節(jié)之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季節(jié)之章:冬
日期:2019-10-10 10:57:17CU大牛徽章
日期:2014-02-21 14:22:52CU大牛徽章
日期:2014-03-13 10:40:30CU大牛徽章
日期:2014-02-21 14:23:15
2 [報(bào)告]
發(fā)表于 2014-03-28 15:11 |只看該作者
本帖最后由 seesea2517 于 2014-03-28 15:12 編輯

回復(fù) 1# ccnuzxg


    是啊,<() 這個(gè)語(yǔ)法是bash特性。用臨時(shí)文件就好了唄。

quote 標(biāo)簽會(huì)解釋出表情來(lái),看來(lái)還是code標(biāo)簽好啊。
  1. Things bash has that sh does not:
  2.    long invocation options
  3.    [+-]O invocation option
  4.    -l invocation option
  5.    `!' reserved word to invert pipeline return value
  6.    `time' reserved word to time pipelines and shell builtins
  7.    the `function' reserved word
  8.    the `select' compound command and reserved word
  9.    arithmetic for command: for ((expr1 ; expr2; expr3 )); do list; done
  10.    new ...' and $"..." quoting
  11.    the $(...) form of command substitution
  12.    the $(<filename) form of command substitution, equivalent to
  13.       $(cat filename)
  14.    the ${#param} parameter value length operator
  15.    the ${!param} indirect parameter expansion operator
  16.    the ${!param*} prefix expansion operator
  17.    the ${param:offset[:length]} parameter substring operator
  18.    the ${param/pat[/string]} parameter pattern substitution operator
  19.    expansions to perform substring removal (${p%[%]w}, ${p#[#]w})
  20.    expansion of positional parameters beyond $9 with ${num}
  21.    variables: BASH, BASH_VERSION, BASH_VERSINFO, UID, EUID, REPLY,
  22.          TIMEFORMAT, PPID, PWD, OLDPWD, SHLVL, RANDOM, SECONDS,
  23.          LINENO, HISTCMD, HOSTTYPE, OSTYPE, MACHTYPE, HOSTNAME,
  24.          ENV, PS3, PS4, DIRSTACK, PIPESTATUS, HISTSIZE, HISTFILE,
  25.          HISTFILESIZE, HISTCONTROL, HISTIGNORE, GLOBIGNORE, GROUPS,
  26.          PROMPT_COMMAND, FCEDIT, FIGNORE, IGNOREEOF, INPUTRC,
  27.          SHELLOPTS, OPTERR, HOSTFILE, TMOUT, FUNCNAME, histchars,
  28.          auto_resume
  29.    DEBUG trap
  30.    ERR trap
  31.    variable arrays with new compound assignment syntax
  32.    redirections: <>, &>, >|, <<<, [n]<&word-, [n]>&word-
  33.    prompt string special char translation and variable expansion
  34.    auto-export of variables in initial environment
  35.    command search finds functions before builtins
  36.    bash return builtin will exit a file sourced with `.'
  37.    builtins: cd -/-L/-P, exec -l/-c/-a, echo -e/-E, hash -d/-l/-p/-t.
  38.         export -n/-f/-p/name=value, pwd -L/-P,
  39.         read -e/-p/-a/-t/-n/-d/-s/-u,
  40.         readonly -a/-f/name=value, trap -l, set +o,
  41.         set -b/-m/-o option/-h/-p/-B/-C/-H/-P,
  42.         unset -f/-v, ulimit -i/-m/-p/-q/-u/-x,
  43.         type -a/-p/-t/-f/-P, suspend -f, kill -n,
  44.         test -o optname/s1 == s2/s1 < s2/s1 > s2/-nt/-ot/-ef/-O/-G/-S
  45.    bash reads ~/.bashrc for interactive shells, $ENV for non-interactive
  46.    bash restricted shell mode is more extensive
  47.    bash allows functions and variables with the same name
  48.    brace expansion
  49.    tilde expansion
  50.    arithmetic expansion with $((...)) and `let' builtin
  51.    the `[[...]]' extended conditional command
  52.    process substitution
  53.    aliases and alias/unalias builtins
  54.    local variables in functions and `local' builtin
  55.    readline and command-line editing with programmable completion
  56.    command history and history/fc builtins
  57.    csh-like history expansion
  58.    other new bash builtins: bind, command, compgen, complete, builtin,
  59.              declare/typeset, dirs, enable, fc, help,
  60.              history, logout, popd, pushd, disown, shopt,
  61.              printf
  62.    exported functions
  63.    filename generation when using output redirection (command >a*)
  64.    POSIX.2-style globbing character classes
  65.    POSIX.2-style globbing equivalence classes
  66.    POSIX.2-style globbing collating symbols
  67.    egrep-like extended pattern matching operators
  68.    case-insensitive pattern matching and globbing
  69.    variable assignments preceding commands affect only that command,
  70.       even for builtins and functions
  71.    posix mode and strict posix conformance
  72.    redirection to /dev/fd/N, /dev/stdin, /dev/stdout, /dev/stderr,
  73.       /dev/tcp/host/port, /dev/udp/host/port
  74.    debugger support, including `caller' builtin and new variables
  75.    RETURN trap
  76.    the `+=' assignment operator
  77. Things sh has that bash does not:
  78.    uses variable SHACCT to do shell accounting
  79.    includes `stop' builtin (bash can use alias stop='kill -s STOP')
  80.    `newgrp' builtin
  81.    turns on job control if called as `jsh'
  82.    $TIMEOUT (like bash $TMOUT)
  83.    `^' is a synonym for `|'
  84.    new SVR4.2 sh builtins: mldmode, priv
  85. Implementation differences:
  86.    redirection to/from compound commands causes sh to create a subshell
  87.    bash does not allow unbalanced quotes; sh silently inserts them at EOF
  88.    bash does not mess with signal 11
  89.    sh sets (euid, egid) to (uid, gid) if -p not supplied and uid < 100
  90.    bash splits only the results of expansions on IFS, using POSIX.2
  91.       field splitting rules; sh splits all words on IFS
  92.    sh does not allow MAILCHECK to be unset (?)
  93.    sh does not allow traps on SIGALRM or SIGCHLD
  94.    bash allows multiple option arguments when invoked (e.g. -x -v);
  95.       sh allows only a single option argument (`sh -x -v' attempts
  96.       to open a file named `-v', and, on SunOS 4.1.4, dumps core.
  97.       On Solaris 2.4 and earlier versions, sh goes into an infinite
  98.       loop.)
  99.    sh exits a script if any builtin fails; bash exits only if one of
  100.       the POSIX.2 `special' builtins fails
復(fù)制代碼

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2014-03-28 15:25 |只看該作者
回復(fù) 2# seesea2517

原來(lái)如此,除了臨時(shí)文件還有沒(méi)有其他簡(jiǎn)單的招數(shù)


   

論壇徽章:
23
15-16賽季CBA聯(lián)賽之吉林
日期: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聯(lián)賽之山東
日期:2017-12-21 16:39:1915-16賽季CBA聯(lián)賽之廣東
日期:2016-01-19 13:33:372015亞冠之山東魯能
日期:2015-10-13 09:39:062015亞冠之西悉尼流浪者
日期:2015-09-21 08:27:57
4 [報(bào)告]
發(fā)表于 2014-03-28 15:40 |只看該作者
回復(fù) 3# ccnuzxg


try:
  1. echo "$str1 $str2" | sed -r ':a;s/\<(.+)\>(.*)\<\1\>/\2/;ta'
復(fù)制代碼

論壇徽章:
93
2015年辭舊歲徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年紀(jì)念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大;照
日期:2019-10-10 10:55:38季節(jié)之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季節(jié)之章:冬
日期:2019-10-10 10:57:17CU大;照
日期:2014-02-21 14:22:52CU大;照
日期:2014-03-13 10:40:30CU大;照
日期:2014-02-21 14:23:15
5 [報(bào)告]
發(fā)表于 2014-03-28 15:40 |只看該作者
回復(fù) 3# ccnuzxg


    用bash嘛。。。。想了想沒(méi)別的簡(jiǎn)單方案了……

論壇徽章:
93
2015年辭舊歲徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年紀(jì)念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大;照
日期:2019-10-10 10:55:38季節(jié)之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季節(jié)之章:冬
日期:2019-10-10 10:57:17CU大;照
日期:2014-02-21 14:22:52CU大;照
日期:2014-03-13 10:40:30CU大;照
日期:2014-02-21 14:23:15
6 [報(bào)告]
發(fā)表于 2014-03-28 15:47 |只看該作者
seesea2517 發(fā)表于 2014-03-28 15:40
回復(fù) 3# ccnuzxg


對(duì)于sh的重定向的辦法而言。

如果為了達(dá)到你腳本語(yǔ)句的功能,則可以這樣(當(dāng)然多個(gè)空格,要不要這么追求完美呢?):
  1. [seesea@UC ~]$ echo "$str1" | tr -d "${str2// }"
  2. 1  3
  3. [seesea@UC ~]$ echo "$str1" | sed -r "s/${str2// /|}//g"
  4. 1  3
復(fù)制代碼

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2014-03-28 17:16 |只看該作者
回復(fù) 4# ly5066113

多謝,不過(guò)代碼看不懂啊,還有2個(gè)問(wèn)題

剔除的時(shí)候會(huì)多個(gè)空格,還有一種情況,如果str2不在str1中,應(yīng)該是打印出str1 不是str1+str2


   

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2014-03-28 17:17 |只看該作者
回復(fù) 6# seesea2517

代碼不錯(cuò),
不過(guò)俺確實(shí)是完美主義,
中間會(huì)多出空格,怎么破

   

論壇徽章:
93
2015年辭舊歲徽章
日期:2019-10-10 10:51:15CU大;照
日期:2014-02-21 14:21:56CU十二周年紀(jì)念徽章
日期:2020-10-15 16:55:55CU大;照
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大;照
日期:2019-10-10 10:55:38季節(jié)之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季節(jié)之章:冬
日期:2019-10-10 10:57:17CU大;照
日期:2014-02-21 14:22:52CU大;照
日期:2014-03-13 10:40:30CU大;照
日期:2014-02-21 14:23:15
9 [報(bào)告]
發(fā)表于 2014-03-28 17:19 |只看該作者
回復(fù) 8# ccnuzxg

空格過(guò)濾一下嘍:
  1. [seesea@UC ~]$ echo "$str1" | tr -d "${str2// }" | tr -s " "
  2. 1 3
  3. [seesea@UC ~]$ echo "$str1" | sed -r "s/${str2// /|}//g; s/ +/ /g"
  4. 1 3
復(fù)制代碼

論壇徽章:
0
10 [報(bào)告]
發(fā)表于 2014-03-28 17:45 |只看該作者
回復(fù) 9# seesea2517

完美解決了 膜拜。。。


   
您需要登錄后才可以回帖 登錄 | 注冊(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