looking for some solutions? You are welcome.

SOLVED: replace space with ":" in command

SHAH AKASH:

when I write a command that gives me output like that.

[root@localhost:~] esxcli storage filesystem list 
Mount Point                                        Volume Name  UUID                                 Mounted  Type             Size          Free
-------------------------------------------------  -----------  -----------------------------------  -------  ------  -------------  ------------
/vmfs/volumes/5bc0c1e3-2ff435d4-533e-3cd92b0a6096  datastore1   5bc0c1e3-2ff435d4-533e-3cd92b0a6096     true  VMFS-6  1992327954432  589864894464
/vmfs/volumes/50696371-d628af73-35da-9c895c95504a               50696371-d628af73-35da-9c895c95504a     true  vfat        261853184      69218304
/vmfs/volumes/8a820f75-48ed9387-b688-b249a3a1691f               8a820f75-48ed9387-b688-b249a3a1691f     true  vfat        261853184     261844992
/vmfs/volumes/5bc0c1e4-863d9324-d91f-3cd92b0a6096               5bc0c1e4-863d9324-d91f-3cd92b0a6096     true  vfat       4293591040    4260233216
/vmfs/volumes/5bc0c1dd-09ac4bba-56c7-3cd92b0a6096               5bc0c1dd-09ac4bba-56c7-3cd92b0a6096     true  vfat        299712512      80486400

now I want all line which start with "/" and replaces space with ":"

so I try a command esxcli storage filesystem list | sed -e 's/\s\+/:/g' |awk '$1 ~ /^\/[a-z]+/ {print $1$2$3$4$5}and esxcli storage filesystem list |awk '$1 ~ /^\/[a-z]+/ {i=":";print $1i$2i$3i$4i$5i}'

which gives me an output like:

[root@localhost:~] esxcli storage filesystem list | sed -e 's/\s\+/:/g' |awk '$1 ~ /^\/[a-z]+/ {print $1$2$3$4$5}'
/vmfs/volumes/5bc0c1e3-2ff435d4-533e-3cd92b0a6096:datastore1:5bc0c1e3-2ff435d4-533e-3cd92b0a6096:true:VMFS-6:1992327954432:590073561088
/vmfs/volumes/50696371-d628af73-35da-9c895c95504a:50696371-d628af73-35da-9c895c95504a:true:vfat:261853184:69218304
/vmfs/volumes/8a820f75-48ed9387-b688-b249a3a1691f:8a820f75-48ed9387-b688-b249a3a1691f:true:vfat:261853184:261844992
/vmfs/volumes/5bc0c1e4-863d9324-d91f-3cd92b0a6096:5bc0c1e4-863d9324-d91f-3cd92b0a6096:true:vfat:4293591040:4260954112
/vmfs/volumes/5bc0c1dd-09ac4bba-56c7-3cd92b0a6096:5bc0c1dd-09ac4bba-56c7-3cd92b0a6096:true:vfat:299712512:80486400

but the problem is if volume name not found then it should be "::" something like that.

I want output like:

/vmfs/volumes/5bc0c1e3-2ff435d4-533e-3cd92b0a6096:datastore1:5bc0c1e3-2ff435d4-533e-3cd92b0a6096:true:VMFS-6:1992327954432:590073561088
/vmfs/volumes/50696371-d628af73-35da-9c895c95504a::50696371-d628af73-35da-9c895c95504a:true:vfat:261853184:69218304
/vmfs/volumes/8a820f75-48ed9387-b688-b249a3a1691f::8a820f75-48ed9387-b688-b249a3a1691f:true:vfat:261853184:261844992
/vmfs/volumes/5bc0c1e4-863d9324-d91f-3cd92b0a6096:::5bc0c1e4-863d9324-d91f-3cd92b0a6096:true:vfat:4293591040:4260954112
/vmfs/volumes/5bc0c1dd-09ac4bba-56c7-3cd92b0a6096::5bc0c1dd-09ac4bba-56c7-3cd92b0a6096:true:vfat:299712512:80486400



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent