Hi All,
I am having 7 jar files in a dir. abc like listed below
bash-3.00$ cd abc
bash-3.00$ ls
123.jar
23wdawd.jar
dfsa23.jar
dsa.jar
wew234.jar
adsd234234.jar
dfsda423.jar
Now i want to assign all this jar files to a variable in the below format
AB=123.jar:.:23wdawd.jar:dfsa23.jar:dsa.jar:wew234.jar:adsd234234.jar:dfsda423.jar
Note: 1st delimiter will be ":.:" remaining all will be ":"
Any suggestion on how can i achieve this task?
ls -1 | awk 'BEGIN{RS=""}{for(i=1;i<=NF;i++) printf("%s%s", i==2 ? ".:"$i : $i, i<NF ? ":" : "\n")}'
AB=$(ls | paste -sd: - | sed 's/:/:.:/')
Regards,
Alister
Nice one...but to make it work on all flavors of unix the paste command needs to be "paste -sd: -" as legacy unixes dont understand stdin without the - placeholder.
2 Likes
You're absolutely correct. Fixed. Thank you for reminding me of that.
Regards,
Alister
---------- Post updated at 01:00 PM ---------- Previous update was at 01:00 PM ----------
Thanks to all for the quick response ..... ya i got the output which i required. . . .