/app/Appln/logs/
echo Session used server are 'grep -i pid|grep -i session | cut -d'.' -f1 | awk '{print $9}' | sort | uniq'
Output -
lxserver01
lxserver02
lxserver03
When I grep session pid in logs server details I can see above distinct server details but I want to print output like
Session used server are :- lxserver01,lxserver02,lxserver03
With a looong pipe like that, you could certainly add a tr '\n' ',' to achieve what you need. On the other hand, as you deploy awk anyhow, why not do ALL of it in one awk script?
AND, why use the -ltr options to ls when you need the file name only?
The two grep s for "log" and "session" are somewhat redundant, as "log" HAS to be in the file names due to the pattern for the ls command, and "session" as well could be added to the pattern.
Since many versions of awk do not include a sorting function and you seem to want sorted output (although it isn't clear if you want unique sorted output or just need sort to get unique output), you might try a simpler pipeline:
If the cut in this pipeline is just getting rid of .log at the end of your filenames, the sort -u can be removed from the pipeline and you'll still get the same results.
Note that the above pipeline uses a comma as the separator between filenames instead of the <tab> used as the default by paste . If you want the delimiter to be <comma><space> sometimes and just <comma> sometimes (as in your latest ";i'expected output to print[/i]"), you'll need to find another way to do that. (The paste utility only uses single characters as field delimiters, and you'll need to very clearly define the conditions under which each of the various delimiters you want to use are supposed to be chosen as the delimiter between output filenames!)
Do you need all the detail provided by the ls -l ? It might be easier to write a bit like this:-
for file in *log # Loop for each file matching. You may want to use *session*log instead
do
printf "${file%%.*}\n" # Write the part up to the first full-stop to STDOUT, hopefully a Built-In shell command rather than a new shell that echo may give
done | sort -u # Process the STDOUT of the loop to give unique entries
You may, of course, need to add more around it to carry on with the processing.