String parsing help across multiple UNIX platforms
Need to parse XML like strings from a file.
Using `egrep -A 1 "Panel Temp" "$2" | tail -2` I get the following string:
I want to output:
The 9.5 C is the value of 9 * unit of 0.1 C
I need something that'll work from a shell script on old and new systems. Particularly from IRIX 6.5...Linux 2.4 to Linix 2.6+ kernel based systems.
Korn ksh is the default shell on IRIX and is probably the most limiting factor, i.e. ksh features that'll work on old and new.
Any help appreciated
Moderator's Comments:
edit by bakunin: please use CODE-tags (for data and terminal output too). Thank you.
As often stated: one can do that, but be aware that in a strict sense you can't do it by regular exprerssions. For instance, in XML it is not guaranteed that tags are on the same line. They could be on different lines, in different order, etc.. Therefore any regexp-based solution short of a real XML-parser will make implicit assumptions about the format of the file which could or could not be correct.
Quote:
Originally Posted by harleyvrodred
I get the following string:
I want to output:
The 9.5 C is the value of 9 * unit of 0.1 C
OK, the part "9 * 0.1" is perhaps a typo and should (i suppose) read "95 * 0.1". I also understand the format of the string you cut out which containsthe relevant tags. But the command producing this string looks fishy. Can you please post a part of your input file (a few lines surrounding the part you want to cut out and parse), because i think this cutting could be done more easily.
Quote:
Originally Posted by harleyvrodred
Korn ksh is the default shell on IRIX and is probably the most limiting factor, i.e. ksh features that'll work on old and new.
As it is i don't think so: ksh comes in two variants, ksh88 and ksh93 and ksh88 is a strict subset of what ksh93 can do. Find out what IRIX uses, but i think writing for ksh88 should put you on the safe side.
Linux, though, is a different matter, depending on what distribution you use. SuSE 11 for instance, had a real AT&T ksh93 when you installed it and called ksh on the command line. SuSE 12, though, dropped the AT&T version from the repository completely and if you invoke ksh you get some "mksh" (which is a not-compatible clone with most ksh-features missing but some bash-features included), but it won't tell you so. I learned that a few weeks ago, when i gave a script i wrote on RHEL (which again has a real ksh when you invoke ksh) to a colleague from the Linux team and we wondered why it didn't work. So be prepared for some surprises.
This does indeed find every instance and print them out. Nice job!
What I need is for it to find the last instance and return that last one in a string variable so I can pass it onto the next step.
Do you have such an eloquent example of how this might be accomplished as well?
Much appreciated!
Without knowing what shell you're using, we can only guess at how the output of a command should be assigned to a shell variable. And, without knowing what operating system you're using, we have to make several other wild assumption that may not work in your environment, but the following seems to do what you seem to what on the MacOS system I'm using when using a Korn shell:
The command syntax in this script should work with other shells that perform basic command substitutions as required by the POSIX standards (such as bash). If you want to try this on a Solaris/SunOS system, you'll need to change awk to /usr/xpg4/bin/awk or nawk.
The above is a slight variation on the code RudiC suggested that only prints the last occurrence of the data pattern found in the input file,, save the result in a shell variable, and prints the contents of that shell variable before the script exits.
If a file named file contains the sample contents you provided in post #4 in this thread, the output produced by running the above script is:
Last edited by Don Cragun; 06-09-2017 at 05:34 AM..
Reason: Fix typo pointed out by RudiC: s/FS pat FS/FS pattern FS/
This User Gave Thanks to Don Cragun For This Post:
from the CLI on a Mac, if you type networksetup -listallnetworkservices then you get results in a multi-line paragraph that look something like this:
networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Wi-Fi
Display Ethernet
Bluetooth DUN... (7 Replies)
Hi,
I have a string which can be completely unstructred. I am looking to parse out values within that String.
Here is an example
<Random Strings> String1=<some number a> String2=<some number b> String3=<some number c> Satish=<some number d> String4=<some number e>
I only want to parse out... (1 Reply)
Can somebody refer me following multicheck to perform across most of unix platform like AIX, HP-UX, solaris, Linux.
CPU utilization above X%
Check IO above X%
Swap usage check above X%
Memory utilization above X% ... (3 Replies)
I got multple sql files.such as
>>vi abc.sql
select A.SITENAME,
NULL
NULL
A.CREATE_DTM
NULL
A.MODIFY_DTM
NULL
FROM ${STG_RET_ITEM} A INNER JOIN ${STG_INC_COMP} B ON (A.CUSTID=B.CUSTID)
LEFT OUTER JOIN ( select C.SITEID,SITESTATUS,MIN_EFF_DT,CURR_ST_DT,MAX_IN_DT,MAX_ACT_DT
from... (4 Replies)
I need to find the MAC address of the ethernet cards on the host machine from the C language. I have found a way to do this on Linux using socket(), ioctl() and the ifreq structure. But this does not seem to work on AIX, HP/UX and probably the others I need (Solaris, SCO, Alpha etc).
Is there a... (7 Replies)
Hi all
I've been working on a bash script parsing through debug/trace files and extracting all lines that relate to some search string. So far, it works pretty well. However, I am challenged by one requirement that is still open.
What I want to do:
1) parse through a file and identify all... (3 Replies)
Hey guys,
I have this file generated by me... i want to create some HTML output from it.
The problem is that i am really confused about how do I go about reading the file.
The file is in the following format:
TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Does anyone know of any tools that manage the rollout of patches across multiple types of Unix platform ( eg Solaris, Aix etc ).
I am looking for something that does a similiar job to SMS or WSUS in the Windows world (3 Replies)