help writing script

hi all
i am having a file(a fixed length file) of 28 bytes.The file has account number from 5th place to next 16 digits.
the file looks like below,

58331600563588885696ACXT5263
58331600563588885697ACXT5263
58331600563588885698ACXT5263

i want to write a script which will extract the account number from 5th palce to length 16 and append ' before and afeter that and , after each line except the last one.
my out put should look like

'600563588885696',
'600563588885697',
'600563588885698'

please help me in writing a shell script

What's the purpose - would appreciate a reply as it sounds like homework. Simple enough though:

cat filename | cut -c6-20 | sed -e"s/^/'/;s/$/'/"

Whoops :slight_smile: didn't see the ',' - your part of the homework? Easy enough as well, but grades should be earned.

Cheers,

Keith

my purpose was to add a ',' after each line except the last one.can u please guide me how to do this

no need for cat.

cut -c6-20 filename | sed .....

cut -c "6-20" am|awk '{print "`",$1,"`"}'

how can i add comma after each line except the last one

cut -c "6-20" am|sed -e"s/^/'/;s/$/',/"|sed '$s/,//'

Cheers,
K

cut -c6-20 awks | sed "s/^/'/;s/$/',/" |sed -n '$!p' |sed '$s/\,//'

Try this command

awk 'NR==1{r=substr($0,6,16);next}
{print q r q ","}END{print q r q}' q="'" file