How to zip files with same name but different extension?Terminal command to add a directory to many existing zip filesFind files with same name but different content?zip a directory that name start with `-`How can I ignore “zip warning: name not matched” when using zip command with -d option?ZIP files with size limitHow to move files to files with same name, but different extensionHow to zip multiple directories into individual zip filesHow to handle Extraction of two zip files in same folder which contain files with same nameUnzip gz archives with zip extensionbash - Find All Files with Same Name Regardless of ExtensionNested Zip files

How dangerous is XSS

Can compressed videos be decoded back to their uncompresed original format?

Knowledge-based authentication using Domain-driven Design in C#

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

Why didn't Boeing produce its own regional jet?

Rotate ASCII Art by 45 Degrees

In Bayesian inference, why are some terms dropped from the posterior predictive?

Convert seconds to minutes

How can a day be of 24 hours?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

Sums of two squares in arithmetic progressions

What is a Samsaran Word™?

Standard deduction V. mortgage interest deduction - is it basically only for the rich?

Different meanings of こわい

What is required to make GPS signals available indoors?

What do you call someone who asks many questions?

Could the museum Saturn V's be refitted for one more flight?

How to prevent "they're falling in love" trope

How can saying a song's name be a copyright violation?

How to travel to Japan while expressing milk?

What is an equivalently powerful replacement spell for Yuan-Ti's Suggestion spell?

Processor speed limited at 0.4 Ghz

Did 'Cinema Songs' exist during Hiranyakshipu's time?

Is this draw by repetition?



How to zip files with same name but different extension?


Terminal command to add a directory to many existing zip filesFind files with same name but different content?zip a directory that name start with `-`How can I ignore “zip warning: name not matched” when using zip command with -d option?ZIP files with size limitHow to move files to files with same name, but different extensionHow to zip multiple directories into individual zip filesHow to handle Extraction of two zip files in same folder which contain files with same nameUnzip gz archives with zip extensionbash - Find All Files with Same Name Regardless of ExtensionNested Zip files













1















I have a large directory with files like this:



file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc


and I would like to create zip files like:



file1.zip
file2.zip


I have tried



ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*


But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.



zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*









share|improve this question
























  • @Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with sed 's/.[a-z]*//g' | uniq.

    – Michael
    Jan 15 '18 at 5:10











  • have you tried this. zip file1.zip file1.* & zip file2.zip file2.*

    – Mongrel
    Jan 15 '18 at 5:11







  • 4





    for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done

    – Theophrastus
    Jan 15 '18 at 5:27












  • In what directory are the files to be zipped located? I see an ls of the current working directory and an argument to zip of the ~/TEMP directory.

    – Mark Plotnick
    Jan 15 '18 at 5:33











  • @Theophrastus Brilliant. H=$Q%%.* is neat.

    – Michael
    Jan 15 '18 at 5:33















1















I have a large directory with files like this:



file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc


and I would like to create zip files like:



file1.zip
file2.zip


I have tried



ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*


But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.



zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*









share|improve this question
























  • @Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with sed 's/.[a-z]*//g' | uniq.

    – Michael
    Jan 15 '18 at 5:10











  • have you tried this. zip file1.zip file1.* & zip file2.zip file2.*

    – Mongrel
    Jan 15 '18 at 5:11







  • 4





    for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done

    – Theophrastus
    Jan 15 '18 at 5:27












  • In what directory are the files to be zipped located? I see an ls of the current working directory and an argument to zip of the ~/TEMP directory.

    – Mark Plotnick
    Jan 15 '18 at 5:33











  • @Theophrastus Brilliant. H=$Q%%.* is neat.

    – Michael
    Jan 15 '18 at 5:33













1












1








1


0






I have a large directory with files like this:



file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc


and I would like to create zip files like:



file1.zip
file2.zip


I have tried



ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*


But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.



zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*









share|improve this question
















I have a large directory with files like this:



file1.txt
file1.meta
file1.csv
file2.txt
file2.meta
file2.csv
file2.abc


and I would like to create zip files like:



file1.zip
file2.zip


I have tried



ls -1 ~/TEMP | sed 's/.[a-z]*//g' | uniq | awk 'print $NF' | xargs -i zip .zip ~/TEMP/.*


But that just gives an error message that the file cannot be fund. The problem is with the wildcard * I guess.



zip error: Nothing to do! (file1.zip)
zip warning: name not matched: /home/user/TEMP/file.*






bash zip






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 15 '18 at 5:35







Michael

















asked Jan 15 '18 at 4:44









MichaelMichael

1063




1063












  • @Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with sed 's/.[a-z]*//g' | uniq.

    – Michael
    Jan 15 '18 at 5:10











  • have you tried this. zip file1.zip file1.* & zip file2.zip file2.*

    – Mongrel
    Jan 15 '18 at 5:11







  • 4





    for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done

    – Theophrastus
    Jan 15 '18 at 5:27












  • In what directory are the files to be zipped located? I see an ls of the current working directory and an argument to zip of the ~/TEMP directory.

    – Mark Plotnick
    Jan 15 '18 at 5:33











  • @Theophrastus Brilliant. H=$Q%%.* is neat.

    – Michael
    Jan 15 '18 at 5:33

















  • @Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with sed 's/.[a-z]*//g' | uniq.

    – Michael
    Jan 15 '18 at 5:10











  • have you tried this. zip file1.zip file1.* & zip file2.zip file2.*

    – Mongrel
    Jan 15 '18 at 5:11







  • 4





    for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done

    – Theophrastus
    Jan 15 '18 at 5:27












  • In what directory are the files to be zipped located? I see an ls of the current working directory and an argument to zip of the ~/TEMP directory.

    – Mark Plotnick
    Jan 15 '18 at 5:33











  • @Theophrastus Brilliant. H=$Q%%.* is neat.

    – Michael
    Jan 15 '18 at 5:33
















@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with sed 's/.[a-z]*//g' | uniq.

– Michael
Jan 15 '18 at 5:10





@Theophrastus The folder has ~ 200000 files with different basenames, 'file' was just an example. I tried to get the unique basenames with sed 's/.[a-z]*//g' | uniq.

– Michael
Jan 15 '18 at 5:10













have you tried this. zip file1.zip file1.* & zip file2.zip file2.*

– Mongrel
Jan 15 '18 at 5:11






have you tried this. zip file1.zip file1.* & zip file2.zip file2.*

– Mongrel
Jan 15 '18 at 5:11





4




4





for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done

– Theophrastus
Jan 15 '18 at 5:27






for Q in *;do H=$Q%%.*;zip "$H.zip" "$Q";done

– Theophrastus
Jan 15 '18 at 5:27














In what directory are the files to be zipped located? I see an ls of the current working directory and an argument to zip of the ~/TEMP directory.

– Mark Plotnick
Jan 15 '18 at 5:33





In what directory are the files to be zipped located? I see an ls of the current working directory and an argument to zip of the ~/TEMP directory.

– Mark Plotnick
Jan 15 '18 at 5:33













@Theophrastus Brilliant. H=$Q%%.* is neat.

– Michael
Jan 15 '18 at 5:33





@Theophrastus Brilliant. H=$Q%%.* is neat.

– Michael
Jan 15 '18 at 5:33










2 Answers
2






active

oldest

votes


















1














One way, in bash (since you tagged it):




  1. Gather the list of filename prefixes into an associative array:



    declare -A prefixes
    for f in *; do prefixes[$f%%.*]=1; done



  2. Loop through the prefixes and create the zip files:



    for p in "$!prefixes[@]"; do zip "$p" "$p".*; done






share|improve this answer






























    0














    Spinning off from Jeff's idea, but not using a list:



    for fname in *.*; do
    prefix=$fname%.*
    [ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
    zip "$prefix" "$prefix".*
    done


    This loop over all names in the current directory that contains at least one dot character.



    The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %% in place of % to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.



    If the file is a regular file (or symlink to one), and if the archive file does not exist, zip is invoked to create the archive.






    share|improve this answer























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f417163%2fhow-to-zip-files-with-same-name-but-different-extension%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      One way, in bash (since you tagged it):




      1. Gather the list of filename prefixes into an associative array:



        declare -A prefixes
        for f in *; do prefixes[$f%%.*]=1; done



      2. Loop through the prefixes and create the zip files:



        for p in "$!prefixes[@]"; do zip "$p" "$p".*; done






      share|improve this answer



























        1














        One way, in bash (since you tagged it):




        1. Gather the list of filename prefixes into an associative array:



          declare -A prefixes
          for f in *; do prefixes[$f%%.*]=1; done



        2. Loop through the prefixes and create the zip files:



          for p in "$!prefixes[@]"; do zip "$p" "$p".*; done






        share|improve this answer

























          1












          1








          1







          One way, in bash (since you tagged it):




          1. Gather the list of filename prefixes into an associative array:



            declare -A prefixes
            for f in *; do prefixes[$f%%.*]=1; done



          2. Loop through the prefixes and create the zip files:



            for p in "$!prefixes[@]"; do zip "$p" "$p".*; done






          share|improve this answer













          One way, in bash (since you tagged it):




          1. Gather the list of filename prefixes into an associative array:



            declare -A prefixes
            for f in *; do prefixes[$f%%.*]=1; done



          2. Loop through the prefixes and create the zip files:



            for p in "$!prefixes[@]"; do zip "$p" "$p".*; done







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 20 '18 at 1:43









          Jeff SchallerJeff Schaller

          44.5k1162143




          44.5k1162143























              0














              Spinning off from Jeff's idea, but not using a list:



              for fname in *.*; do
              prefix=$fname%.*
              [ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
              zip "$prefix" "$prefix".*
              done


              This loop over all names in the current directory that contains at least one dot character.



              The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %% in place of % to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.



              If the file is a regular file (or symlink to one), and if the archive file does not exist, zip is invoked to create the archive.






              share|improve this answer



























                0














                Spinning off from Jeff's idea, but not using a list:



                for fname in *.*; do
                prefix=$fname%.*
                [ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
                zip "$prefix" "$prefix".*
                done


                This loop over all names in the current directory that contains at least one dot character.



                The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %% in place of % to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.



                If the file is a regular file (or symlink to one), and if the archive file does not exist, zip is invoked to create the archive.






                share|improve this answer

























                  0












                  0








                  0







                  Spinning off from Jeff's idea, but not using a list:



                  for fname in *.*; do
                  prefix=$fname%.*
                  [ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
                  zip "$prefix" "$prefix".*
                  done


                  This loop over all names in the current directory that contains at least one dot character.



                  The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %% in place of % to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.



                  If the file is a regular file (or symlink to one), and if the archive file does not exist, zip is invoked to create the archive.






                  share|improve this answer













                  Spinning off from Jeff's idea, but not using a list:



                  for fname in *.*; do
                  prefix=$fname%.*
                  [ ! -f "$fname" ] || [ -f "$prefix.zip" ] && continue
                  zip "$prefix" "$prefix".*
                  done


                  This loop over all names in the current directory that contains at least one dot character.



                  The body of the loop extracts the filename prefix by removing the bit after the last dot in the current filename (use %% in place of % to remove from the first dot). It then tests whether the name was actually the name of a regular file (or a symbolic link to one) and whether the corresponding Zip archive for that file already exists or not.



                  If the file is a regular file (or symlink to one), and if the archive file does not exist, zip is invoked to create the archive.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 2 days ago









                  KusalanandaKusalananda

                  139k17259430




                  139k17259430



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f417163%2fhow-to-zip-files-with-same-name-but-different-extension%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

                      Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

                      Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.