Here Description tag is not available in some cases. In that case i would like to display a hardcoded value. Can you please suggest with how to solve this.
Similarly if you want to need any other line(you haven't told us which description exactly you need to add) you can replace the BOLD one with the desired one and try.
If you have any queries please do let us know with complete input and complete expected output.
I would guess that you're using a Solaris/SunOS system. On Solaris/SunOS systems, you need to change awk to /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk . If this is NOT the case, it is advisable always so show us
errors you are getting don't let us guess, we will be able to help you more on same.
Glad that it helped you, following is the explaination for same.
awk '/<Emp:Profile>/ {print $0;getline;if($0 ~ /<Emp:Description>/){print $0;next} else {printf "\t\t\t<Emp:Description>Admin</Emp:Description>" ORS $0 ORS;next}} 1' Input_file
/<Emp:Profile>/ # Searching for String Emp:Profile
print $0;getline # When match found then printing that line and going to next line
if($0 ~ /<Emp:Description>/) # Now checking a conditon if nect line's data is having string <Emp:Description>
print $0;next # Print that description line and then skip all next statements by next keyword.
else # When a step above if condition doesn't satisfy then
printf "\t\t\t<Emp:Description>Admin</Emp:Description>" ORS $0 ORS;next # Print the desired string then ORS(Output record seprator which is a new line by default and current line.)
next # leave all further statements now
1 # awk works on condition then statement pattern so making conditin TRUE by printing 1 and then it will perform default action which is PRINT as I haven't mentioned any action there.