Thread: Setting the next line of a file to something if the above is something
i trying variable set next line if line above matches criteria, know line above is, not line below.
so, example of contents of file:
i know cfbundledisplayname is, not next line down (dismount).code:<key>cfbundledisplayname</key> <string>dismount</string>
next line (dismount), want set variable (not <string> , </string> in though)
have spent hour messing around code try , read right (i change variable names)
but alas, don't know how works, code taken answer have received before different question, , changed stuff around try , working. succesfully reads cfbundledisplayname line, , knows found it, don't know how set next line variable "$theme".code:plutil -convert xml1 /applications/preferences.app/info.plist themefile=$(</applications/preferences.app/info.plist) theme="none" line in $themefile; #trim off whitespaces line2=${line%%<} line3=${line2#<key>} line3=${line3%</key>} #now see if key if [ "$line2:0:5" == "<string>" ]; #got key line #need trim off xml tags line4=${line2#<string>} line4=${line4%</string>} theme=$line4; elif [ "$line3" == "cfbundledisplayname" ]; #found true line, setting variable $command :) echo "found it" fi done echo "$theme"
thank
-brian
since input xml, , question has perfect formulation in terms of xml, suggest use xml routines. xpath, example:
if use xml lot, xpath worth learning.code:$ cat data.xml <data> <key>cfbundledisplayname</key> <string>dismount</string> </data> $ xpath -q -e '//*[preceding-sibling::key]/text()' data.xml dismount
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk [SOLVED] Setting the next line of a file to something if the above is something
Ubuntu

Comments
Post a Comment