linux - Centos shell script - Group files starting with the same string -


i have directory many pdf files. each file name starts numeric id (5 chars fixed length), follows:

11111-2014.pdf   11111-2015.pdf   22222-2015.pdf   33333-2013.pdf   33333-2014.pdf   33333-2015.pdf   

i'm trying figure out how write shell script in centos reads files in such directory , list them depending on id. shell script should return following output (on 3 rows) following:

11111-2014.pdf 11111-2015.pdf   22222-2015.pdf   33333-2013.pdf 33333-2014.pdf 33333-2015.pdf   

and assign each row variable name (ie: $rowstring).

i group in string files starting same id, , attach them same email using mutt email client command line. so, following above example:

for each unique $rowstring command be:

mutt -s "subject" $rowstring -- abc@domain.com < body.txt   

where $rowstring (the attachments) should follows
first email:

-a 11111-2014.pdf -a 11111-2015.pdf 

for second email:

-a 22222-2014.pdf   

for third email:

-a 33333-2013.pdf -a 33333-2014.pdf -a 33333-2015.pdf 

i tried combine ls , awk commands i'm newbie succeed. everybody.

the following command:

 ls  | awk -f '-' 'begin{temp=""} temp&&$1!=temp{printf "\n"} {printf "-a %s ",$0; temp = $1}' 

outputs:

-a 11111-2014.pdf -a 11111-2015.pdf -a 22222-2015.pdf -a 33333-2013.pdf -a 33333-2014.pdf -a 33333-2015.pdf 

you can use each line 1 @ time , send mail.


Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -