-1

In an Amazon s3 bucket we have Debian packages stored in different folders each folder contains different amount of files.
While calling Debian packages from the s3 bucket(AWS) the packages are separated with spaces. Now I need to convert those space-separated packages into a newline-separated list, i.e. one package file per line. The input line doesn't contain an equal amount of spaces.
Each directory contains a different number of Debian packages and at last after converting packages into line-by-line will store all packages(of the different folders) in one file.

input:

package1.deb  package2.deb     pacakge3.deb        pacakge4.deb package5.deb 

output:

package1.deb  
package2.deb  
package3.deb  
pacakge4.deb

This is the current attempt for a function running in the background for different folders of s3 bucket

function convertSpaceToNewLine(){
for line in filename; do
   cat $line| grep '.deb$'|tr [:space:] \\t | sed 's/\t\t*/\n/g' >> folder/newfile
done
}

I have tried many commands like truncate, awk, xargs -n 1, and sed. Thanks

Rehana
  • 1
  • 2

1 Answers1

0

I think using sed to replace spaces with newline would be sufficient.

$ echo package1.deb    package2.deb    pacakge3.deb        pacakge4.deb   package5.deb | sed 's/ /\n/g' 

package1.deb
package2.deb
pacakge3.deb
pacakge4.deb
package5.deb

Harsh
  • 77
  • 2
  • 8
  • sorry those packages are present in different folders and there are in millions so only sed command won't work – Rehana Jan 19 '23 at 06:40
  • 1
    @Harsh In your solution, the command that gets rid of the duplicated spaces is `echo`, not `sed` – Fravadona Jan 19 '23 at 08:29