Hi,
I am having the file with server names & its corresponding process, i need your help how to convert into comma separated output between server & app
#cat apps.txt
Server1
oracle
was
Server2
http
webadmin
Server3
tsm
db2
My requirement is like below.
Server1,oracle/was
Server2,http/webadmin
Server3,tsm/db2
RudiC
2
Easy with paste
:
paste -s -d',/\n' file
Server1,oracle/was
Server2,http/webadmin
Server3,tsm/db2
Hi Rudic, Thanks for your quick tip
having 1 more doubt, how to use paste command for the following
#cat apps.txt
Server1
oracle
Server2
http
webadmin
oracle
Server3
tsm
webadm
The output required as follows
Server1,oracle
Server2,http/webadmin/oracle
Server3,tsm/webadm
rdrtx1
4
for gnu flavor awk try:
awk '$1=$1 {sub("/",","); sub("/$",""); print RS $0}' RS="Server" FS="\n" OFS=/ apps.txt
RudiC
5
Easy with awk:
awk '$1 ~ /Server/ {printf "\n"; printf "%s,", $1; SL=""; next}
{printf "%s%s", SL, $1; SL="/"}
END {printf "\n"}
' file
Server1,oracle
Server2,http/webadmin/oracle
Server3,tsm/webadm
1 Like
Hi Rudic,
No words to explain.. U r great. Thanks ..
Regards,
Siva