I need to print the below word in new line using the delimiter in shell script.
INPUT
sring=aru :muth:ram:pak
OUTPUT
aru
muth
ram
pak
I need to print the below word in new line using the delimiter in shell script.
INPUT
sring=aru :muth:ram:pak
OUTPUT
aru
muth
ram
pak
Hello ramkumar15,
For shown input following may help you.
echo "sring=aru :muth:ram:pak" | awk -F"[:=]" '{print $2 ORS $3 ORS $4 ORS $5}'
Output will be as follows.
aru
muth
ram
pak
Thanks,
R. Singh
Try
sed 's/ //g;s/:/\n/g;s/sring=//' file
aru
muth
ram
pak
This is GNU sed
. Other sed
s might not like the \n
; use an adequate <newline> representation, then.
string='aryn:muth:ram'
sed 's/ //g;s/:/\n/g;s/string=//' file
Is this correct. I am writing a shell script for the above program it should print in every line.
---------- Post updated at 04:40 AM ---------- Previous update was at 04:38 AM ----------
hi ravinder,
i have multiple fields to be printed in the line using the delimieter :.
I could see you have mentioned only for 3-5 fields.
Hello ramkumar15,
Could you please try following and let me know if this helps you.
echo "sring=aru :muth:ram:pak" | awk -F"[:=]" '{$1="";$0=$0;sub(/^[[:space:]]/,X,$0)} 1' OFS="\n"
Thanks,
R. Singh
thanks a lot its work now.
WHAT do you want? Do you have a line of text (like in post#1) to be analyzed, or the contents of a string (as in post#4), or a script file with variable assignments, including spaces, or not, or WHAT?
Please be way more precise and careful with your specifications!