Been using an example I found here (https://stackoverflow.com/a/14397390/3168446) and I just noticed it's not adding items correctly. The following example is actually adding items outside of the channel-tag. Anyone know the correct way to make this work?
feed.xml:
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>My RSS Feed</title>
<description>This is my RSS Feed</description>
</channel>
</rss>
shell script:
#!/bin/sh
TITLE="My RSS entry"
LINK="http://example.com/entry4711"
DATE="`date`"
DESC="Good news"
GUID="http://example.com/entry4711"
xmlstarlet ed -L -a "//channel" -t elem -n item -v "" \
-s "//item[1]" -t elem -n title -v "$TITLE" \
-s "//item[1]" -t elem -n link -v "$LINK" \
-s "//item[1]" -t elem -n pubDate -v "$DATE" \
-s "//item[1]" -t elem -n description -v "$DESC" \
-s "//item[1]" -t elem -n guid -v "$GUID" \
-d "//item[position()>10]" feed.xml ;
windows command line example:
xml ed -L -a "//channel" -t elem -n item -v "" -s "//item[1]" -t elem -n title -v "My RSS entry" -s "//item[1]" -t elem -n link -v "http://example.com/entry4711" -s "//item[1]" -t elem -n pubDate -v "Sat, 26 Jul 2014 01:14:30 +0200" -s "//item[1]" -t elem -n description -v "Good news" -s "//item[1]" -t elem -n guid -v "http://example.com/entry4711" -d "//item[position()>10]" feed.xml
output feed.xml:
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>My RSS Feed</title>
<description>This is my RSS Feed</description>
</channel>
<item>
<title>My RSS entry</title>
<link>http://example.com/entry4711</link>
<pubDate>Sat, 26 Jul 2014 01:14:30 +0200</pubDate>
<description>Good news</description>
<guid>http://example.com/entry4711</guid>
</item>
</rss>
As you see in the output the item is added outside of the channel-tag so the feed won't validate.
Wasn't actually that hard after a good night sleep.
The reason every item is added outside of the channel tag is because I used;
xml ed -L -a "//channel"
Solution is to use a tag in the feed-template that is not used within the items you're adding. I'm using the generator-tag.
Example feed.xml with added generator-tag:
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>My RSS Feed</title>
<description>This is my RSS Feed</description>
<link>http://example.com/entry4711</link>
<generator>your-rss-generator</generator>
</channel>
</rss>
Shell script where I replace //channel with //generator:
#!/bin/sh
TITLE="My RSS entry"
LINK="http://example.com/entry4711"
DATE="`date`"
DESC="Good news"
GUID="http://example.com/entry4711"
xmlstarlet ed -L -a "//generator" -t elem -n item -v "" \
-s "//item[1]" -t elem -n title -v "$TITLE" \
-s "//item[1]" -t elem -n link -v "$LINK" \
-s "//item[1]" -t elem -n pubDate -v "$DATE" \
-s "//item[1]" -t elem -n description -v "$DESC" \
-s "//item[1]" -t elem -n guid -v "$GUID" \
-d "//item[position()>10]" feed.xml ;
Windows command line where I replace //channel with //generator:
xml ed -L -a "//generator" -t elem -n item -v "" -s "//item[1]" -t elem -n title -v "My RSS entry" -s "//item[1]" -t elem -n link -v "http://example.com/entry4711" -s "//item[1]" -t elem -n pubDate -v "Sat, 26 Jul 2014 01:14:30 +0200" -s "//item[1]" -t elem -n description -v "Good news" -s "//item[1]" -t elem -n guid -v "http://example.com/entry4711" -d "//item[position()>10]" feed.xml
This will make every new item go within the channel-tag.
Related
I am using neovim and tmux (with tmuxinator) with the ultimate goal of getting https://github.com/christoomey/vim-tmux-navigator setup on my M1 Macbook with iTerm2 or Warp (https://www.warp.dev/)
I have mapped my left option key to be my meta key in my terminal. I would like to use <M-h/j/k/l> in order to navigate between neovim splits and tmux panes. Mapping my left option key to meta and using it with h/j/k/l works as expected in neovim (including neovim in tmux - i.e. i can navigate neovim splits and go from neovim to a tmux terminal pane). However, in a tmux terminal pane it either does nothing in iTerm2 or brings up alternate text (˙∆˚¬ for hjkl to be specific) in Warp.
Below are my configurations which were from https://github.com/christoomey/vim-tmux-navigator and i just updated them to use meta instead of ctrl:
init.vim
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <M-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <M-j> :TmuxNavigateDown<cr>
nnoremap <silent> <M-k> :TmuxNavigateUp<cr>
nnoremap <silent> <M-l> :TmuxNavigateRight<cr>
nnoremap <silent> <M-\> :TmuxNavigatePrevious<cr>
.tmux.conf
unbind M-h
unbind M-j
unbind M-k
unbind M-l
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'M-h' if-shell "$is_vim" 'send-keys M-h' 'select-pane -L'
bind-key -n 'M-j' if-shell "$is_vim" 'send-keys M-j' 'select-pane -D'
bind-key -n 'M-k' if-shell "$is_vim" 'send-keys M-k' 'select-pane -U'
bind-key -n 'M-l' if-shell "$is_vim" 'send-keys M-l' 'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'M-\\' if-shell \"$is_vim\" 'send-keys M-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'M-\\' if-shell \"$is_vim\" 'send-keys M-\\\\' 'select-pane -l'"
bind-key -T copy-mode-vi 'M-h' select-pane -L
bind-key -T copy-mode-vi 'M-j' select-pane -D
bind-key -T copy-mode-vi 'M-k' select-pane -U
bind-key -T copy-mode-vi 'M-l' select-pane -R
bind-key -T copy-mode-vi 'M-\' select-pane -l
How can i get this to work? I would be happy to get it working on either terminal.
I am trying to do AES-CBC cipher and decipher via openssl, however, I am not able to get the correct output. Please advise me. Thank you.
cipher
clr;
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a"
IV="00000000000000000000000000000000"
KEY="00000000000000000000000000000000"
echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
decipher
clr;
MSG_CIPHERED_HEX="734563526574204d6553734167452030300a0e0e0e0e0e0e0e0e0e0e0e0e0e0e"
echo $MSG_CIPHERED_HEX
MSG_ASCII=echo $MSG_HEX | xxd -p -r | tr -d '\n'; echo $MSG_ASCII > tmp.ciphered.file.ascii;
openssl enc -d -aes-128-cbc -K $KEY -iv $IV -in tmp.ciphered.file.ascii -out out.txt
cat out.txt | xxd -p # | tr -d '\n'
rm -rf tmp.ciphered.file.ascii out.txt
There seemed to be data formatting issue:
$ #decipher
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV="00000000000000000000000000000000" KEY="00000000000000000000000000000000" echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -d -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
Ans:
734563526574204d6553734167452030300a (truncated)
$ #cipher
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV="00000000000000000000000000000000" KEY="00000000000000000000000000000000" echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
Ans:
236999001256bd4131dffa3417c29bfc597a43f6bde387ba0e42da86e67cfff42890e4f6e84c0e70753a9db754df996e
The e0e0e0e0e0e0e0e0e0e0e0e0e0e is 14 bytes of padding. If you specify padding on decryption it will be automatically removed.
See PKCS7 padding.
I am using the command:
xmlstarlet ed --omit-decl --subnode "/boinc" --type elem -n app -v "" project_00.xml > project_01.xml
However, I would like to insert two more tags into that one:
<app>
<name>name</name>
<nikname>nikname</nikname>
</app>
In my project_00.xml, I already have others tag app and it is causing conflicts.
The problem with this command:
xmlstarlet ed --subnode "/boinc" --type elem -n app -v "" project_00.xml| xmlstarlet ed --subnode //app --type elem -n name -v "newApp"| xmlstarlet ed --subnode //app --type elem -n user_friendly_name -v "New.App" > project_01.xml
is that it created this.:
<app name="wilson">
<name>wilson</name>
<user_friendly_name>Mr.Wilson</user_friendly_name>
<name>newApp</name>
<user_friendly_name>New.App</user_friendly_name>
</app>
<app>
<name>newApp</name>
<user_friendly_name>New.App</user_friendly_name>
</app>
Does know the exactly command?
I tried this command but it replicated the to all app tags
xmlstarlet ed -s "/boinc" -t elem -n app -v "" -s "/boinc/app" -t elem -n name -v "name" -s "/boinc/app" -t elem -n user_friendly_name -v "New.App" project_00.xml > project_01.xml
Basically, you need an XPath expression to match the node you just inserted; since --subnode always puts new children in last place you can use /boinc/app[last()]:
xmlstarlet ed \
--subnode /boinc --type elem -n app -v '' \
--subnode '/boinc/app[last()]' --type elem -n name -v newApp \
--subnode '/boinc/app[last()]' --type elem -n user_friendly_name -v New.App \
project_00.xml > project_01.xml
With this example XML:
<rootnode>
<element-a />
<element-b />
<element-d />
<element-e />
</rootnode>
How do I insert element <element-c/> directly after the element <element-b/> using XMLStarlet?
xml ed -i (or --insert) will put the it before the node, xml ed -a (or --append) will put it after, so you can use either one of:
xml ed -i /rootnode/element-d -t elem -n element-c -v "" file.xml
xml ed -a /rootnode/element-b -t elem -n element-c -v "" file.xml
Here is the xml snippet:
$ cat short.xml
<hostnames>
<hostname name="yahoo.com" type="user"/>
<hostname name="ir1.fp.vip.sp2.yahoo.com" type="PTR"/>
</hostnames>
<hostnames>
<hostname name="Inc.com" type="user"/>
<hostname name="www.inc.com" type="PTR"/>
</hostnames>
The desired output is:
yahoo.com | ir1.fp.vip.sp2.yahoo.com
Inc.com | www.inc.com
What I have so far that is only partially working:
$ xml sel -t -m "//hostname" -v "#name" -n short.xml
I cannot seem to trap the Type= condition properly. TIA.
Two more solutions using xmlstarlet only once (no need to iterate):
xmlstr='
<root>
<hostnames>
<hostname name="yahoo.com" type="user"/>
<hostname name="ir1.fp.vip.sp2.yahoo.com" type="PTR"/>
</hostnames>
<hostnames>
<hostname name="Inc.com" type="user"/>
<hostname name="www.inc.com" type="PTR"/>
</hostnames>
</root>
'
echo "$xmlstr" | xmlstarlet sel -T -t -m "//hostnames" -m "hostname[#type='user']" -v '#name' -o " | " -b -m "hostname[#type='PTR']" -v '#name' -n
echo "$xmlstr" | xmlstarlet sel -T -t -m "//hostname" -i "#type='user'" -v '#name' -o " | " -b -i "#type='PTR'" -v '#name' -n
You need to count the hostnames with xmlstarlet el or something and then iterate with something like:
xmlstarlet sel -t -c "//hostnames[1]" short.xml | xmlstarlet sel -t -m "//hostname/#name" -v . -o ' | '
This would be a lot easier if the XML was better designed. :)
The example given in question is invalid xml.
xmlstarlet --version
1.3.1
compiled against libxml2 2.8.0, linked with 20800
compiled against libxslt 1.1.26, linked with 10126
xmlstarlet val -e short.xml
short.xml:5.1: Extra content at the end of the document
<hostnames>
^
short.xml - invalid
The idea in the answer by mitm is quite nice cure.
$ xml sel -t -m //hostnames -v "concat(hostname[1]/#name,'|',hostname[2]/#name)" -n file.xml
$ xml sel -t -m //hostnames -v hostname[1]/#name -o "|" -v hostname[2]/#name -n file.xml
$ xml sel -t -m //hostname[#type='user'] -v #name -o "|" -v following-sibling::hostname/#name -n file.xml