how to read xml file in linux
You can use this sed
,
sed -n '/LANGUAGE/{N; s/.*<string>\(.*\)<\/string>.*/\1/p; }' Locale.xml
How to parse XML using shellscript?
You could try xmllint
The xmllint program parses one or more
XML files, specified on the command
line as xmlfile. It prints various
types of output, depending upon the
options selected. It is useful for
detecting errors both in XML code and
in the XML parser itse
It allows you select elements in the XML doc by xpath, using the --pattern option.
On Mac OS X (Yosemite), it is installed by default.
On Ubuntu, if it is not already installed, you can run apt-get install libxml2-utils
Linux xml parse
The stuff before a colon is a name space prefix. You need to register the namespace and use it in the XPath expressions:
setns s=urn:S2SCTIcf:xsd:$SCTIcfBlkCredTrf
cat //s:FDtTm/text()
So, the whole script can be something like
#!/bin/bash
ext=$(cat <<'EOF' \
| xmllint --shell file.xml \
| grep -A1 -- '-------' \
| tail -n1
setns s=urn:S2SCTIcf:xsd:$SCTIcfBlkCredTrf
cat //s:FileRef/text()
EOF
)
echo "$ext"
How to read XML and write to text file using shell script?
Try following and let me know if this helps you.
awk '
/<\/Data>/{
a="";
next
}
/<Data>/{
a=1;
next
}
/location/ && a{
gsub(/\"|>/,"",$NF);
location=$NF;
next
}
/Name/ && a{
name=$2;
next
}
/ID/ && a{
print "Name : ",name RS "ID: ",$2 RS "Location: ",location;
next
}
' Input_file
As per OP's request sine NO TAGS should be hard coded so adding following solution too now.
EDIT2: I am not a xml expert but tried it here, could you please check once.
awk 'NF==1 && (/ +<[a-zA-Z]+>/ || /^<[a-zA-Z]+>/ || / +<\/[a-zA-Z]+>/){
next
}
{
sub(/^ +/,"")
gsub(/\"|<|>/,"",$0);
sub(/\/.*/,"");
if($0){
print
}
}
' Input_file
How linux daemon will read xml file in worker service .Net Core 3.1
You are right that a Linux daemon will not be able to read paths that dont exist on Linux.
There are a couple of approaches you can look at:
Your services can look at the OS and read a different path/file on Linux. For example, for Windows you are reading the hard-coded location
@'D:\LC2\Files\Config.xml'
, and on Linux, you can use another hard-coded like/opt/LC2/config.xml
.You can provide an argument to the worker service. That requires parsing arguments and teaching your worker service about an argument, like
--config /path/to/file
. Then your worker service will just read that passed-in path and not have to worry about the path. Whatever runs/configures your service will provide a correct path on Windows and on Linux.You can add support for reading the file location via an environment variable like
LC2_CONFIG
. If it's set and points to a file, use that location as the config file. Otherwise fall back to the hard-coded value. On Linux, the tool that runs your daemon can provide it a path that is appropriate for Linux.
There are other options and variants possible, but these seem like the most obvious approaches.
Depending on the audience of the program, you might want all three. For example, git
will use a default location for a config file. But it will let users provide specific configuration values both via command line and also let users specify configuration via environment variables.
how to parse xml file in C language on linux
Considering you might not need libXML just to extract a few value, and as long as you don't care about the validity of your input, you could load the file in memory ( or part of it ).
char* xmlChunk; // your data will be stored inside
char* tagStartBegin = strstr(xmlChunk,"<pty");
char* tagStartEnd = strstr(tagStartBegin,">");
char* value = tagStartEnd+1;
// get the end tag
char* tagEndBegin = strstr(tagStartEnd,"</pty>");
//end the string here
*tagEndBegin = '\0';
// parse your value
doSomeThing(value);
You might need to adapt your code for unicode input if any
Related Topics
Linux History of All Commands Executed During Whole Day, Everyday
How to Simulate a Usb Printer to Lpt on Linux
Using Ebpf to Measure CPU Mode Switch Overhead Incured by Making System Call
Suppressing Compile Time Linkage of Shared Libraries
How to Get The File System Type for Syscall.Mount() Programmatically
How to Get a Linux Coredump That Only Contains Callstack, Threads, and Local Variables
How to Split My File into Multiple Files
Eclipse Kura Installation on Raspberry Pi 3
Save The Result of Ls Command in The Remote Sftp Server on Local Machine
Udev-How to Get Value of a Child Device Attributes
Bash - Ignore Hidden Files and Empty Source Directory When Copying
Git Wont Reset File Permissions Over Cifs Mount
Shell Script to Find The Nth Occurrence of a String and Print The Line Number
Simpler Way to Repeatedly Read Lines and Invoke a Program
Tcp Keepalive - Protocol Not Available
Selinux Prevented Httpd(Usr/Sbin/Httpd) Write Access to /Var/Www/HTML/Bookings/Templates_C