Linux/Parsing: Difference between revisions

From Wiki
(Die Seite wurde neu angelegt: „* show as hex <blockquote> <pre> od -t x1 -An </pre> </blockquote>“)
 
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
== lines ==
* grep
<blockquote>
<pre>
grep -v ^$        # remove empty lines
</pre>
</blockquote>
* tail
<blockquote>
<pre>
tail
tail -f                # follow
tail -n 10            # last 10 lines
tail +3                # skip first 3 lines
</pre>
</blockquote>
* wc
<blockquote>
<pre>
wc -l                  # count lines
</pre>
</blockquote>
== chars ==
* cut<syntaxhighlight lang="bash">
uname -a
-> Linux nutzer-laptop 3.2.0-030200-generic #201201042035 SMP Thu Jan 5 01:36:31 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
uname -a | cut -d" " -f1,3,12
-> Linux 3.2.0-030200-generic x86_64
</syntaxhighlight>
* tr
* parameter expansion
<syntaxhighlight lang="bash">
</syntaxhighlight>
== directories and files ==
* basename
== sed & awk ==
* sed + control characters
<blockquote>
<pre>
sed 's/\x00/controlcharwashere/g'
</pre>
</blockquote>
<blockquote>
<pre>
sed -n '/Iowa/,/Montana/p'
</pre>
</blockquote>
== other ==
* slowing output
<blockquote>
<pre>
cat incoming.log | pv -qL 1000 | tee temp
</pre>
</blockquote>
* show as hex
* show as hex
<blockquote>
<blockquote>
Line 5: Line 69:
</pre>
</pre>
</blockquote>
</blockquote>
== Links ==
* http://www.unix.com/tips-tutorials/18009-12-ways-parse-file.html
* http://sed.sourceforge.net/sed1line.txt
* http://www.grymoire.com/Unix/Sed.html
[[Category:Linux/Bash]]
[[Category:Linux]]

Latest revision as of 16:24, 24 November 2020

lines

  • grep
grep -v ^$        # remove empty lines
  • tail
tail 
tail -f                # follow
tail -n 10             # last 10 lines
tail +3                # skip first 3 lines 
  • wc
wc -l                  # count lines 

chars

  • cut
    uname -a 
    -> Linux nutzer-laptop 3.2.0-030200-generic #201201042035 SMP Thu Jan 5 01:36:31 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
    
    uname -a | cut -d" " -f1,3,12 
    -> Linux 3.2.0-030200-generic x86_64
    
  • tr
  • parameter expansion

directories and files

  • basename

sed & awk

  • sed + control characters
sed 's/\x00/controlcharwashere/g'
sed -n '/Iowa/,/Montana/p'


other

  • slowing output
cat incoming.log | pv -qL 1000 | tee temp
  • show as hex
od -t x1 -An



Links