由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - Shell programming problem, Thx!
相关主题
IFS shell scriptmakefile 文件是不是可以看作一种shell?
shell script help?makefile help
shell script question[转载] bibliography question
How to extract Last string in one line (Windows NT SHELL script)[转载] a question about text format/process
login shell and normal shell?what's the use of "ta"
how to change login shell?vi 一问.
How to get into directory seperated by spacehow to decrypt a crypted string??
Help, Webserver for Solaris 7how to grep a string in all sub-dirs?
相关话题的讨论汇总
话题: c2话题: lastc2话题: shell话题: lastline话题: first
进入Unix版参与讨论
1 (共1页)
d**m
发帖数: 72
1
I have a text file. There are 2 columns in each line, seperated by \t\t
as follows (c1 and c2 are strings might contain blankspace ):
c1\t\tc2
The lines are sorted by c2
How can I count the appearance of strings c2 and delete all the rows
that c2 appears just once in this file? How can I do that by just using
unix command or using awk or sed?
Thank a lot!
s***e
发帖数: 108
2
#!/usr/bin/awk -f
BEGIN { FS = "\t\t"; lastc2 = "" }
{ if ( lastc2 == $2 ) {
first = first + 1
if ( first == 1 ) {
print lastline "\n" $0
} else {
print $0
}
} else {
first = 0
}
lastline = $0
lastc2 = $2
}

【在 d**m 的大作中提到】
: I have a text file. There are 2 columns in each line, seperated by \t\t
: as follows (c1 and c2 are strings might contain blankspace ):
: c1\t\tc2
: The lines are sorted by c2
: How can I count the appearance of strings c2 and delete all the rows
: that c2 appears just once in this file? How can I do that by just using
: unix command or using awk or sed?
: Thank a lot!

1 (共1页)
进入Unix版参与讨论
相关主题
how to grep a string in all sub-dirs?login shell and normal shell?
[转载] 一个简单的regular expression问题how to change login shell?
question on "strings"How to get into directory seperated by space
UNIX command toHelp, Webserver for Solaris 7
IFS shell scriptmakefile 文件是不是可以看作一种shell?
shell script help?makefile help
shell script question[转载] bibliography question
How to extract Last string in one line (Windows NT SHELL script)[转载] a question about text format/process
相关话题的讨论汇总
话题: c2话题: lastc2话题: shell话题: lastline话题: first