In a Amazon s3 bucket we have Debian packages stored in different folders. Each folder contains different amounts 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 lists into newline-separated list, i.e. one package file per line. The input lines don't contain equal amounts of spaces.
Each directory contains the different numbers of Debian packages and at last after converting packages into line-by-line will store all packages (of different folder) in one folder file.
- input example:
package1.deb package2.deb pacakge3.deb pacakge4.deb package5.deb
- desired output:
package1.deb package2.deb package3.deb pacakge4.deb package5.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 tired many commands like truncate
, awk
, xargs -n 1
, and sed
.
convert
function to find ways of improving that. If you statefor line in filename
, this implies that you are iterating over a list of files, becausecat
is used to output the content of a file. However,filename
is not used as a variable (like in$filename
) but a single string, so thefor
loop would only run once, with$line
set to (literally)filename
. Is that really what you intend to do? – AdminBee Jan 19 '23 at 09:17