如果第 2 和第 3 字段相同,我如何使用排序或其他 bash 命令从所有行中获取 1 行

How Can I Use Sort or another bash cmd To Get 1 line from all the lines if 1st 2nd and 3rd Field are The same

我有一个文件名为 file.txt

$cat file.txt



1./abc/cde/go/ftg133333.jpg

2./abc/cde/go/ftg24555.jpg

3./abc/cde/go/ftg133333.gif

4./abt/cte/come/ftg24555.jpg

5./abc/cde/go/ftg133333.jpg

6./abc/cde/go/ftg24555.pdf
sort -u -t '/' -k1 -k2 -k3

/abc/cde/go/ftg133333KALI.jpg 

/abt/cte/come/ftg24555KALI.jpg

/abc/cde/go/ftg133333KALI.gif

/abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk

  n=split($0,a,/\\//)          # split by / to get all path components

  m=split(a[n],b,".")          # split last by . to get the extension

}

m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs

  for(i=2;i<=n;i++)           # loop component parts and print

    printf"/%s%s",a[i],(i==n?ORS:"")

}' file

/abc/cde/go/ftg133333.jpg

/abc/cde/go/ftg133333.gif

/abt/cte/come/ftg24555.jpg

/abc/cde/go/ftg24555.pdf$ awk '{

  n=split($0,a,/\\//)

  m=split(a[n],b,".")

}

m>1&&!seen[a[2],a[3],a[4],b[m]]++ {

  for(i=2;i<n;i++)

    printf"/%s",a[i]

  for(i=1;i<=m;i++)

    printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]

  print""

}' file

/abc/cde/go/ftg133333KALI.jpg

/abc/cde/go/ftg133333KALI.gif

/abt/cte/come/ftg24555KALI.jpg

/abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file



/abc/cde/go/ftg133333.jpg

/abc/cde/go/ftg133333.gif

/abt/cte/come/ftg24555.jpg

/abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")

      if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0

     }

     END { for (f in files) {

         sub("\\\\.","KALI.", files[f])

         print files[f]

       }}' input.txt 

/abt/cte/come/ftg24555KALI.jpg

/abc/cde/go/ftg133333KALI.gif

/abc/cde/go/ftg24555KALI.pdf

/abc/cde/go/ftg133333KALI.jpg

我的目标:从第一个、第二个和第三个 PATH 相同且具有相同文件扩展名的行中仅获取一行。

请注意,每个 PATH 都由正斜杠"/"分隔。例如,在列表的第一行,第一个 PATH 是 abc,第二个 PATH 是 cde,第三个 PATH 是 go。

文件扩展名是 .jpg、.gif、.pdf... 始终位于行尾。

这是我尝试过的

$cat file.txt



1./abc/cde/go/ftg133333.jpg

2./abc/cde/go/ftg24555.jpg

3./abc/cde/go/ftg133333.gif

4./abt/cte/come/ftg24555.jpg

5./abc/cde/go/ftg133333.jpg

6./abc/cde/go/ftg24555.pdf
sort -u -t '/' -k1 -k2 -k3

/abc/cde/go/ftg133333KALI.jpg 

/abt/cte/come/ftg24555KALI.jpg

/abc/cde/go/ftg133333KALI.gif

/abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk

  n=split($0,a,/\\//)          # split by / to get all path components

  m=split(a[n],b,".")          # split last by . to get the extension

}

m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs

  for(i=2;i<=n;i++)           # loop component parts and print

    printf"/%s%s",a[i],(i==n?ORS:"")

}' file

/abc/cde/go/ftg133333.jpg

/abc/cde/go/ftg133333.gif

/abt/cte/come/ftg24555.jpg

/abc/cde/go/ftg24555.pdf$ awk '{

  n=split($0,a,/\\//)

  m=split(a[n],b,".")

}

m>1&&!seen[a[2],a[3],a[4],b[m]]++ {

  for(i=2;i<n;i++)

    printf"/%s",a[i]

  for(i=1;i<=m;i++)

    printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]

  print""

}' file

/abc/cde/go/ftg133333KALI.jpg

/abc/cde/go/ftg133333KALI.gif

/abt/cte/come/ftg24555KALI.jpg

/abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file



/abc/cde/go/ftg133333.jpg

/abc/cde/go/ftg133333.gif

/abt/cte/come/ftg24555.jpg

/abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")

      if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0

     }

     END { for (f in files) {

         sub("\\\\.","KALI.", files[f])

         print files[f]

       }}' input.txt 

/abt/cte/come/ftg24555KALI.jpg

/abc/cde/go/ftg133333KALI.gif

/abc/cde/go/ftg24555KALI.pdf

/abc/cde/go/ftg133333KALI.jpg

我的想法

使用 / 作为分隔符给我每行 4 个字段。使用"-u"对它们进行排序将删除除 1 行之外的所有内容,其中包含唯一的第一、第二和第三个字段/路径。但显然,在这种情况下,我没有考虑 EXTENSION(jpg,pdf,gif)。

我的问题

  • 如果第一个、第二个和第三个字段相同并且具有相同的 EXTENSION 使用"/"作为分隔符将其划分为字段,我需要一种方法来 grep 仅其中一行。我想将它输出到另一个文件,比如 file2.txt.

  • 在 file2.txt 中,如何在每行的扩展名前添加一个单词"KALI",所以它看起来像 /abc/cde/go/ftg13333KALI.jpg 使用第 1 行作为文件中的示例.txt 以上。

  • 期望的输出

    $cat file.txt
    
    
    
    1./abc/cde/go/ftg133333.jpg
    
    2./abc/cde/go/ftg24555.jpg
    
    3./abc/cde/go/ftg133333.gif
    
    4./abt/cte/come/ftg24555.jpg
    
    5./abc/cde/go/ftg133333.jpg
    
    6./abc/cde/go/ftg24555.pdf
    sort -u -t '/' -k1 -k2 -k3
    
    /abc/cde/go/ftg133333KALI.jpg 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk
    
      n=split($0,a,/\\//)          # split by / to get all path components
    
      m=split(a[n],b,".")          # split last by . to get the extension
    
    }
    
    m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs
    
      for(i=2;i<=n;i++)           # loop component parts and print
    
        printf"/%s%s",a[i],(i==n?ORS:"")
    
    }' file
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk '{
    
      n=split($0,a,/\\//)
    
      m=split(a[n],b,".")
    
    }
    
    m>1&&!seen[a[2],a[3],a[4],b[m]]++ {
    
      for(i=2;i<n;i++)
    
        printf"/%s",a[i]
    
      for(i=1;i<=m;i++)
    
        printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]
    
      print""
    
    }' file
    
    /abc/cde/go/ftg133333KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file
    
    
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")
    
          if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0
    
         }
    
         END { for (f in files) {
    
             sub("\\\\.","KALI.", files[f])
    
             print files[f]
    
           }}' input.txt 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf
    
    /abc/cde/go/ftg133333KALI.jpg

    评论

  • 第 1,2 行


    $cat file.txt
    
    
    
    1./abc/cde/go/ftg133333.jpg
    
    2./abc/cde/go/ftg24555.jpg
    
    3./abc/cde/go/ftg133333.gif
    
    4./abt/cte/come/ftg24555.jpg
    
    5./abc/cde/go/ftg133333.jpg
    
    6./abc/cde/go/ftg24555.pdf
    sort -u -t '/' -k1 -k2 -k3
    
    /abc/cde/go/ftg133333KALI.jpg 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk
    
      n=split($0,a,/\\//)          # split by / to get all path components
    
      m=split(a[n],b,".")          # split last by . to get the extension
    
    }
    
    m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs
    
      for(i=2;i<=n;i++)           # loop component parts and print
    
        printf"/%s%s",a[i],(i==n?ORS:"")
    
    }' file
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk '{
    
      n=split($0,a,/\\//)
    
      m=split(a[n],b,".")
    
    }
    
    m>1&&!seen[a[2],a[3],a[4],b[m]]++ {
    
      for(i=2;i<n;i++)
    
        printf"/%s",a[i]
    
      for(i=1;i<=m;i++)
    
        printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]
    
      print""
    
    }' file
    
    /abc/cde/go/ftg133333KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file
    
    
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")
    
          if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0
    
         }
    
         END { for (f in files) {
    
             sub("\\\\.","KALI.", files[f])
    
             print files[f]
    
           }}' input.txt 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf
    
    /abc/cde/go/ftg133333KALI.jpg

    输出:

    $cat file.txt
    
    
    
    1./abc/cde/go/ftg133333.jpg
    
    2./abc/cde/go/ftg24555.jpg
    
    3./abc/cde/go/ftg133333.gif
    
    4./abt/cte/come/ftg24555.jpg
    
    5./abc/cde/go/ftg133333.jpg
    
    6./abc/cde/go/ftg24555.pdf
    sort -u -t '/' -k1 -k2 -k3
    
    /abc/cde/go/ftg133333KALI.jpg 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk
    
      n=split($0,a,/\\//)          # split by / to get all path components
    
      m=split(a[n],b,".")          # split last by . to get the extension
    
    }
    
    m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs
    
      for(i=2;i<=n;i++)           # loop component parts and print
    
        printf"/%s%s",a[i],(i==n?ORS:"")
    
    }' file
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk '{
    
      n=split($0,a,/\\//)
    
      m=split(a[n],b,".")
    
    }
    
    m>1&&!seen[a[2],a[3],a[4],b[m]]++ {
    
      for(i=2;i<n;i++)
    
        printf"/%s",a[i]
    
      for(i=1;i<=m;i++)
    
        printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]
    
      print""
    
    }' file
    
    /abc/cde/go/ftg133333KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file
    
    
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")
    
          if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0
    
         }
    
         END { for (f in files) {
    
             sub("\\\\.","KALI.", files[f])
    
             print files[f]
    
           }}' input.txt 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf
    
    /abc/cde/go/ftg133333KALI.jpg

    I split by /. 分开,以防目录名称中有 .

    错过了 KALI 部分:

    $cat file.txt
    
    
    
    1./abc/cde/go/ftg133333.jpg
    
    2./abc/cde/go/ftg24555.jpg
    
    3./abc/cde/go/ftg133333.gif
    
    4./abt/cte/come/ftg24555.jpg
    
    5./abc/cde/go/ftg133333.jpg
    
    6./abc/cde/go/ftg24555.pdf
    sort -u -t '/' -k1 -k2 -k3
    
    /abc/cde/go/ftg133333KALI.jpg 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk
    
      n=split($0,a,/\\//)          # split by / to get all path components
    
      m=split(a[n],b,".")          # split last by . to get the extension
    
    }
    
    m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs
    
      for(i=2;i<=n;i++)           # loop component parts and print
    
        printf"/%s%s",a[i],(i==n?ORS:"")
    
    }' file
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk '{
    
      n=split($0,a,/\\//)
    
      m=split(a[n],b,".")
    
    }
    
    m>1&&!seen[a[2],a[3],a[4],b[m]]++ {
    
      for(i=2;i<n;i++)
    
        printf"/%s",a[i]
    
      for(i=1;i<=m;i++)
    
        printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]
    
      print""
    
    }' file
    
    /abc/cde/go/ftg133333KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file
    
    
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")
    
          if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0
    
         }
    
         END { for (f in files) {
    
             sub("\\\\.","KALI.", files[f])
    
             print files[f]
    
           }}' input.txt 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf
    
    /abc/cde/go/ftg133333KALI.jpg

    输出:

    $cat file.txt
    
    
    
    1./abc/cde/go/ftg133333.jpg
    
    2./abc/cde/go/ftg24555.jpg
    
    3./abc/cde/go/ftg133333.gif
    
    4./abt/cte/come/ftg24555.jpg
    
    5./abc/cde/go/ftg133333.jpg
    
    6./abc/cde/go/ftg24555.pdf
    sort -u -t '/' -k1 -k2 -k3
    
    /abc/cde/go/ftg133333KALI.jpg 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk
    
      n=split($0,a,/\\//)          # split by / to get all path components
    
      m=split(a[n],b,".")          # split last by . to get the extension
    
    }
    
    m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs
    
      for(i=2;i<=n;i++)           # loop component parts and print
    
        printf"/%s%s",a[i],(i==n?ORS:"")
    
    }' file
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk '{
    
      n=split($0,a,/\\//)
    
      m=split(a[n],b,".")
    
    }
    
    m>1&&!seen[a[2],a[3],a[4],b[m]]++ {
    
      for(i=2;i<n;i++)
    
        printf"/%s",a[i]
    
      for(i=1;i<=m;i++)
    
        printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]
    
      print""
    
    }' file
    
    /abc/cde/go/ftg133333KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file
    
    
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")
    
          if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0
    
         }
    
         END { for (f in files) {
    
             sub("\\\\.","KALI.", files[f])
    
             print files[f]
    
           }}' input.txt 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf
    
    /abc/cde/go/ftg133333KALI.jpg

    另一个awk

    $cat file.txt
    
    
    
    1./abc/cde/go/ftg133333.jpg
    
    2./abc/cde/go/ftg24555.jpg
    
    3./abc/cde/go/ftg133333.gif
    
    4./abt/cte/come/ftg24555.jpg
    
    5./abc/cde/go/ftg133333.jpg
    
    6./abc/cde/go/ftg24555.pdf
    sort -u -t '/' -k1 -k2 -k3
    
    /abc/cde/go/ftg133333KALI.jpg 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk
    
      n=split($0,a,/\\//)          # split by / to get all path components
    
      m=split(a[n],b,".")          # split last by . to get the extension
    
    }
    
    m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs
    
      for(i=2;i<=n;i++)           # loop component parts and print
    
        printf"/%s%s",a[i],(i==n?ORS:"")
    
    }' file
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk '{
    
      n=split($0,a,/\\//)
    
      m=split(a[n],b,".")
    
    }
    
    m>1&&!seen[a[2],a[3],a[4],b[m]]++ {
    
      for(i=2;i<n;i++)
    
        printf"/%s",a[i]
    
      for(i=1;i<=m;i++)
    
        printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]
    
      print""
    
    }' file
    
    /abc/cde/go/ftg133333KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file
    
    
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")
    
          if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0
    
         }
    
         END { for (f in files) {
    
             sub("\\\\.","KALI.", files[f])
    
             print files[f]
    
           }}' input.txt 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf
    
    /abc/cde/go/ftg133333KALI.jpg

    假定目录名称中不存在 .(通常不一定正确)。


    使用 awk:

    $cat file.txt
    
    
    
    1./abc/cde/go/ftg133333.jpg
    
    2./abc/cde/go/ftg24555.jpg
    
    3./abc/cde/go/ftg133333.gif
    
    4./abt/cte/come/ftg24555.jpg
    
    5./abc/cde/go/ftg133333.jpg
    
    6./abc/cde/go/ftg24555.pdf
    sort -u -t '/' -k1 -k2 -k3
    
    /abc/cde/go/ftg133333KALI.jpg 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf$ awk '{                 # using awk
    
      n=split($0,a,/\\//)          # split by / to get all path components
    
      m=split(a[n],b,".")          # split last by . to get the extension
    
    }
    
    m>1 && !seen[a[2],a[3],a[4],b[m]]++ {   # if ext exists and is unique with 3 1st dirs
    
      for(i=2;i<=n;i++)           # loop component parts and print
    
        printf"/%s%s",a[i],(i==n?ORS:"")
    
    }' file
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk '{
    
      n=split($0,a,/\\//)
    
      m=split(a[n],b,".")
    
    }
    
    m>1&&!seen[a[2],a[3],a[4],b[m]]++ {
    
      for(i=2;i<n;i++)
    
        printf"/%s",a[i]
    
      for(i=1;i<=m;i++)
    
        printf"%s%s",(i==1?"/":(i==m?"KALI.":".")),b[i]
    
      print""
    
    }' file
    
    /abc/cde/go/ftg133333KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg24555KALI.pdf$ awk -F'[./]' '!a[$2,$3,$4,$NF]++' file
    
    
    
    /abc/cde/go/ftg133333.jpg
    
    /abc/cde/go/ftg133333.gif
    
    /abt/cte/come/ftg24555.jpg
    
    /abc/cde/go/ftg24555.pdf$ awk -F/ '{ split($5, ext,"\\\\.")
    
          if (!(($2,$3,$4,ext[2]) in files)) files[$2,$3,$4,ext[2]]=$0
    
         }
    
         END { for (f in files) {
    
             sub("\\\\.","KALI.", files[f])
    
             print files[f]
    
           }}' input.txt 
    
    /abt/cte/come/ftg24555KALI.jpg
    
    /abc/cde/go/ftg133333KALI.gif
    
    /abc/cde/go/ftg24555KALI.pdf
    
    /abc/cde/go/ftg133333KALI.jpg

相关推荐

  • Spring部署设置openshift

    Springdeploymentsettingsopenshift我有一个问题让我抓狂了三天。我根据OpenShift帐户上的教程部署了spring-eap6-quickstart代码。我已配置调试选项,并且已将Eclipse工作区与OpehShift服务器同步-服务器上的一切工作正常,但在Eclipse中出现无法消除的错误。我有这个错误:cvc-complex-type.2.4.a:Invali…
    2025-04-161
  • 检查Java中正则表达式中模式的第n次出现

    CheckfornthoccurrenceofpatterninregularexpressioninJava本问题已经有最佳答案,请猛点这里访问。我想使用Java正则表达式检查输入字符串中特定模式的第n次出现。你能建议怎么做吗?这应该可以工作:MatchResultfindNthOccurance(intn,Patternp,CharSequencesrc){Matcherm=p.matcher…
    2025-04-161
  • 如何让 JTable 停留在已编辑的单元格上

    HowtohaveJTablestayingontheeditedcell如果有人编辑JTable的单元格内容并按Enter,则内容会被修改并且表格选择会移动到下一行。是否可以禁止JTable在单元格编辑后转到下一行?原因是我的程序使用ListSelectionListener在单元格选择上同步了其他一些小部件,并且我不想在编辑当前单元格后选择下一行。Enter的默认绑定是名为selectNext…
    2025-04-161
  • Weblogic 12c 部署

    Weblogic12cdeploy我正在尝试将我的应用程序从Tomcat迁移到Weblogic12.2.1.3.0。我能够毫无错误地部署应用程序,但我遇到了与持久性提供程序相关的运行时错误。这是堆栈跟踪:javax.validation.ValidationException:CalltoTraversableResolver.isReachable()threwanexceptionatorg.…
    2025-04-161
  • Resteasy Content-Type 默认值

    ResteasyContent-Typedefaults我正在使用Resteasy编写一个可以返回JSON和XML的应用程序,但可以选择默认为XML。这是我的方法:@GET@Path("/content")@Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON})publicStringcontentListRequestXm…
    2025-04-161
  • 代码不会停止运行,在 Java 中

    thecodedoesn'tstoprunning,inJava我正在用Java解决项目Euler中的问题10,即"Thesumoftheprimesbelow10is2+3+5+7=17.Findthesumofalltheprimesbelowtwomillion."我的代码是packageprojecteuler_1;importjava.math.BigInteger;importjava…
    2025-04-161
  • Out of memory java heap space

    Outofmemoryjavaheapspace我正在尝试将大量文件从服务器发送到多个客户端。当我尝试发送大小为700mb的文件时,它显示了"OutOfMemoryjavaheapspace"错误。我正在使用Netbeans7.1.2版本。我还在属性中尝试了VMoption。但仍然发生同样的错误。我认为阅读整个文件存在一些问题。下面的代码最多可用于300mb。请给我一些建议。提前致谢publicc…
    2025-04-161
  • Log4j 记录到共享日志文件

    Log4jLoggingtoaSharedLogFile有没有办法将log4j日志记录事件写入也被其他应用程序写入的日志文件。其他应用程序可以是非Java应用程序。有什么缺点?锁定问题?格式化?Log4j有一个SocketAppender,它将向服务发送事件,您可以自己实现或使用与Log4j捆绑的简单实现。它还支持syslogd和Windows事件日志,这对于尝试将日志输出与来自非Java应用程序…
    2025-04-161