首页 \ 问答 \ 从Bash文件中删除重复出现的行的最佳方法是什么?(What is the best way of removing reoccurring lines from a file in Bash?)

从Bash文件中删除重复出现的行的最佳方法是什么?(What is the best way of removing reoccurring lines from a file in Bash?)

伙计们,

我有一个包含ldap条目的文件,我想从第二个事件中删除“版本:1”行。 我知道sed可以做这样的事情,但因为我很新,所以我不知道该怎么做。 这是一台Solaris 10机器,该文件如下所示:

version: 1
dn: uid=tuser1,ou=people,o=example.com,o=isp
cn: tuser1
uidNumber: 3
gidNumber: 3
homeDirectory: /export/home/tuser1
loginShell: /bin/sh
objectClass: posixAccount
objectClass: shadowAccount
objectClass: account
objectClass: top
uid: tuser1
shadowLastChange:
userPassword:

version: 1
dn: uid=tuser2,ou=people,o=example.com,o=isp
uidNumber: 20
cn: tuser1
gidNumber: 3
homeDirectory: /export/home/tuser2
loginShell: /bin/sh
objectClass: posixAccount
objectClass: shadowAccount
objectClass: account
objectClass: top
uid: tuser1
shadowLastChange:
userPassword: 

version: 1
dn: uid=tuser3,ou=people,o=example.com,o=isp
uidNumber: 10
cn: tuser3
gidNumber: 3
homeDirectory: /export/home/tuser3
loginShell: /bin/sh
objectClass: posixAccount
objectClass: shadowAccount
objectClass: account
objectClass: top
uid: tuser3
shadowLastChange:
userPassword: 

version: 1
dn: uid=loperp,ou=people,o=example.com,o=isp
uid: loperp
userPassword:
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
sn: pop
cn: loper

version: 1
dn: uid=tuser4,ou=people,o=example.com,o=isp
userPassword: 
uid: tuser4
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
sn: User4
cn: Test

Folks,

I have a file that contains ldap entries and I want to remove "version: 1" lines from the second occurrence and on. I know sed can do things like this, but since I am very new, I don't know how to proceed. This is a Solaris 10 machine and the file looks like as follows:

version: 1
dn: uid=tuser1,ou=people,o=example.com,o=isp
cn: tuser1
uidNumber: 3
gidNumber: 3
homeDirectory: /export/home/tuser1
loginShell: /bin/sh
objectClass: posixAccount
objectClass: shadowAccount
objectClass: account
objectClass: top
uid: tuser1
shadowLastChange:
userPassword:

version: 1
dn: uid=tuser2,ou=people,o=example.com,o=isp
uidNumber: 20
cn: tuser1
gidNumber: 3
homeDirectory: /export/home/tuser2
loginShell: /bin/sh
objectClass: posixAccount
objectClass: shadowAccount
objectClass: account
objectClass: top
uid: tuser1
shadowLastChange:
userPassword: 

version: 1
dn: uid=tuser3,ou=people,o=example.com,o=isp
uidNumber: 10
cn: tuser3
gidNumber: 3
homeDirectory: /export/home/tuser3
loginShell: /bin/sh
objectClass: posixAccount
objectClass: shadowAccount
objectClass: account
objectClass: top
uid: tuser3
shadowLastChange:
userPassword: 

version: 1
dn: uid=loperp,ou=people,o=example.com,o=isp
uid: loperp
userPassword:
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
sn: pop
cn: loper

version: 1
dn: uid=tuser4,ou=people,o=example.com,o=isp
userPassword: 
uid: tuser4
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
sn: User4
cn: Test

原文:https://stackoverflow.com/questions/3087979
更新时间:2022-05-27 07:05

最满意答案

this.test是一个函数,而不是一个数组。 尝试先调用它:

{this.test().map(list => <p> {list.text} </p>)}

this.test is a function, not an array. Try to call it first:

{this.test().map(list => <p> {list.text} </p>)}

相关问答

更多
  • 而不是试图将对象转换为数组,只需将其剪切并直接通过Object.keys数组循环。 render () (
      {Object.keys(this.props.data).map((propKey) => {
    • {this.props.data[propKey]}
        {Object.keys(this.props.data[propKey]).map((ch ...
  • 理想情况下,您将手动指定每个键。 {(schoolData.student || []).map(student => (
    • Name: {student.name}
    • Grade: {student.grade}
    ))} 等等... 但是如果你真的想循环遍历student对象中的变量键,那么基本上你需要遍历学生数组,然后遍历每个学生对象中的键。 这是它的样子: const School = ({ ...
  • 您的shuffle()函数正在对数组进行混洗,这意味着它正在更新this.props.data而不是制作一个单独的混洗版本。 直接更新任何props或state的值通常是一个坏主意,因为它会导致这样的奇怪问题。 如果你想让shuffle函数返回一个混洗的副本,你可以在该函数的顶部添加一行array = array.slice() 。 如果你宁愿离开shuffle ,你可以使用shuffle(this.props.data.slice()).map(...)或shuffle(this.props.data.m ...
  • 问题与responseData ,它是一个对象不是数组,尝试使用 details:responseData.meta.questions Issue is with responseData, it is an object not array, try with details:responseData.meta.questions
  • 将您的forEach()更改为map() 。 forEach()函数没有返回值,所以如果你从那里返回任何东西,它就会被扔掉。 map()函数将收集所有返回值(包括undefined如果不返回任何内容)并将它们作为数组返回。 在你的情况下,你需要使用map() ,然后在地图后面添加.filter(Boolean) ,以删除所有undefined的场景,并且不返回任何东西。 event && interests && interests.map(interest => /* your code */).filt ...
  • 在你的情况下应该工作正常: BooksAPI.search(query).then(res => { if (res instanceof Array && res.length > 0) { booksOnShelves.forEach((book) => { const correspondingRes = res.find((item) => { return (item.id === book.id) }); if (correspondingRes) { book. ...
  • this.test是一个函数,而不是一个数组。 尝试先调用它: {this.test().map(list =>

    {list.text}

    )} this.test is a function, not an array. Try to call it first: {this.test().map(list =>

    {list.text}

    )}
  • 它应该是这样的 getInitialState: function() { return { items: [] }; }, renderArticleHeadline: function(article) { return (
  • {article.headline}
  • ); }, componentDidMount: function() { this.fetchFront ...
  • 确保地图的父容器具有明确的高度和宽度大小。 如果没有这些更改,地图就会显示在那里。 Make sure the parent container of the map has explicit height and width sizes. The map is there it just won't show without these changes.
  • 问题不在于更改密钥的cloneElement 。 如文档中所述,cloneElement保留原始密钥。 它的React.Children.map它添加了一个前缀。 如果您不想更改密钥,请使用forEach而不是map 这是React Code的摘录: function escape(key) { var escapeRegex = /[=:]/g; var escaperLookup = { '=': '=0', ':': '=2', }; var escapedString ...
  • 相关文章

    更多
  • bash shell循环的疑问
  • Java 流(Stream)、文件(File)和IO
  • My W3C Custom Mapping File
  • shell 脚本执行,出现错误bad interpreter: No such file or directory
  • -bash: /bin/mv: Argument list too long的解决方案
  • PHP 中dirname(_file_)
  • bash: scp: command not found的解决方法
  • 【HDFS】HADOOP DISTRIBUTED FILE SYSTEM
  • Securing Solr on Tomcat access using a user account
  • 移动MM failed to find resource file{mmiap.xml}
  • 最新问答

    更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)