Mar 1, 2006 #1 viadisky Technical User Joined Jun 19, 2003 Messages 110 Location GB Hi, I would like to grep 157 from here --> <text_string>157</text_string> I prefer using awk ... please help Cheers!
Hi, I would like to grep 157 from here --> <text_string>157</text_string> I prefer using awk ... please help Cheers!
Mar 1, 2006 1 #2 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO Hi I think you want to clear all XML-like tags, so : Code: awk '{gsub(/<[^<>]*>/,"");print}' /input/file But if you want to extract the value marked by two "text_string" tags, then : Code: awk '{print gensub(/.*<text_string>(.*)<\/text_string>.*/,"\\1","")}' /input/file viadisky said: I prefer using awk Click to expand... I prefer [tt]sed[/tt]. Code: sed 's/<[^<>]*>//g' /input/file [gray]# or[/gray] sed 's/.*<text_string>\(.*\)<\/text_string>.*/\1/' /input/file The second solutions will not work well if there are input lines without that markup. Specify more about the input format if needed. Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi I think you want to clear all XML-like tags, so : Code: awk '{gsub(/<[^<>]*>/,"");print}' /input/file But if you want to extract the value marked by two "text_string" tags, then : Code: awk '{print gensub(/.*<text_string>(.*)<\/text_string>.*/,"\\1","")}' /input/file viadisky said: I prefer using awk Click to expand... I prefer [tt]sed[/tt]. Code: sed 's/<[^<>]*>//g' /input/file [gray]# or[/gray] sed 's/.*<text_string>\(.*\)<\/text_string>.*/\1/' /input/file The second solutions will not work well if there are input lines without that markup. Specify more about the input format if needed. Feherke. http://rootshell.be/~feherke/
Mar 1, 2006 Thread starter #3 viadisky Technical User Joined Jun 19, 2003 Messages 110 Location GB Hi Feherke, Thanks for your suggestion You are absolutely right, sed is better for this type of text manipultaion. It is a lot easier to intergrate it with my script. Cheers, Maria Upvote 0 Downvote
Hi Feherke, Thanks for your suggestion You are absolutely right, sed is better for this type of text manipultaion. It is a lot easier to intergrate it with my script. Cheers, Maria