Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:misc [2025/10/14 12:23] – [Manipulating Strings] tmadelinux:misc [2026/06/12 11:07] (current) – [Set variable] tmade
Line 35: Line 35:
 } }
 </code> </code>
 +
 +====yq====
 +yq - commandline YAML processor, to visualize yaml output in a readable way
 +
 +Example to replace a openshift-route with yq:
 +
 +  oc get route/${route} -o yaml | yq eval '.spec.tls.certificate = strenv(TLSCERT) | .spec.tls.key = strenv(TLSKEY)' - | oc replace -f -
  
 ====Manipulating Strings==== ====Manipulating Strings====
Line 65: Line 72:
 String3 String3
 </code> </code>
 +
 +Another example:
 +<code>
 +# echo ${TEST:-Foo}      #if "TEST" is empty you are getting default value
 +Foo
 +# echo $TEST
 +# echo ${TEST:=Foo}      #if "TEST" is empty it will be set 
 +Foo
 +# echo $TEST
 +Foo
 +</code>
 +
 +====Set variable====
 +Alternative to "sed":
 +
 +  var="oldvalue"
 +  var="${var/oldvalue/newvalue}"
 +  echo $var
 +  newvalue
 +
  
 ====awk==== ====awk====
Line 77: Line 104:
   ifconfig -a | awk '/inet 10/{print $2}'                                                                        #getting IP adress starting with "inet 10"   ifconfig -a | awk '/inet 10/{print $2}'                                                                        #getting IP adress starting with "inet 10"
   echo "somestring1 somestring2" | awk '{print $1,$2}'   echo "somestring1 somestring2" | awk '{print $1,$2}'
 +  awk -F ':' '{print $1 "\t" $4}' /etc/passwd                                                                    #print all username + uid
 +  awk 'length($0) > 18' marks.txt                                                                                #print only those lines that contain more than 18 characters
linux/misc.1760437439.txt.gz · Last modified: by tmade
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki