Posted: . At: 6:28 PM. This was 5 years ago. Post ID: 12677
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Use sed to filter text, this is very useful.


This sed sample will filter out all HTML opening and closing tags in HTML

sed -e 's/<[^>]*>//g' blog.txt

This is an example of the usage of this one-liner.

4.4 Sun Nov 11 jason@Yog-Sothoth 0: $ sed -e 's/<[^>]*>//g' index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
	Securitron GNU/Linux pages.
 
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-16570816-2']);
  _gaq.push(['_trackPageview']);
 
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
 
<?php
    include("menu.php");
?>

replace all newlines with a newline and a tab character.

cat index.php | perl -pe 's/\n/\n\t/'

Converting a comma delimited file to newline delimited. Using sed to perform the conversion.
https://securitronlinux.com/uncategorized/converting-a-comma-delimited-file-to-newline-delimited/.

Find all instances of a word in a text file with egrep.

4.4 Sun Nov 11 jason@Yog-Sothoth 0: $ egrep 'option' < index.php
<option value="0" selected>Image number: 1.</option>
<option value="1">Image number: 2.</option>
<option value="2">Image number: 3.</option>
<option value="3">Image number: 4.</option>
<option value="4">Image number: 5.</option>
<option value="5">Image number: 6.</option>
<option value="6">Image number: 7.</option>

Find and replace the word option with the word number.

4.4 Sun Nov 11 jason@Yog-Sothoth 0: $ sed "s/\option/number: /gi;" index.php
<form action="index.php" method="GET">
<select name="img" size="1">
<number:  value="0" selected>Image number: 1.</number: >
<number:  value="1">Image number: 2.</number: >
<number:  value="2">Image number: 3.</number: >
<number:  value="3">Image number: 4.</number: >
<number:  value="4">Image number: 5.</number: >
<number:  value="5">Image number: 6.</number: >
<number:  value="6">Image number: 7.</number: >
</select>
<button type="submit">Submit</button>
</form>

This is not using cat.

Print numeric permissions for all files in a directory.

4.4 Sun Nov 11 jason@Yog-Sothoth 0: $ find . -printf "%m:%f\n" | sed "s/:/ - /gi;"
777 - .
777 - yadex_15172.c
777 - tank.sh
777 - utmp.c
777 - my.c
777 - iBoot.iso
777 - time.c
777 - my_linux_system.php
777 - my2.c
777 - encode.sh
777 - index.php
777 - index(2).php
777 - myftp.c
777 - linux_configs.php
777 - tiny.asm
777 - program.c
777 - xvid.sh
777 - syscall.c
777 - x11.c

This also works as well.

alias cls="ls -lha --color=always -F --group-directories-first |awk '{k=0;s=0;for(i=0;i<=8;i++){;k+=((substr(\$1,i+2,1)~/[rwxst]/)*2^(8-i));};j=4;for(i=4;i<=10;i+=3){;s+=((substr(\$1,i,1)~/[stST]/)*j);j/=2;};if(k){;printf(\"%0o%0o \",s,k);};print;}'"

Source.

https://stackoverflow.com/a/50686667.

This is the output this will give you.

4.4 Sun Nov 11 jason@Yog-Sothoth 0: $ cls
0200 total 22M
0777 drwxrwxrwx+  2 jason jason 4.0K Dec 24  2013 ./
0755 drwxr-xr-x+ 36 jason jason 4.0K Nov  2 10:10 ../
0777 -rwxrwxrwx   1 jason jason  250 Feb 12  2011 encode.sh*
0777 -rwxrwxrwx   1 jason jason  22M Feb  7  2011 iBoot.iso*
0777 -rwxrwxrwx   1 jason jason 1.7K Feb 27  2011 index(2).php*
0777 -rwxrwxrwx   1 jason jason 2.7K Feb 21  2011 index.php*
0777 -rwxrwxrwx   1 jason jason  51K Feb 20  2011 linux_configs.php*
0777 -rwxrwxrwx   1 jason jason 1.8K Sep 20  2016 my2.c*
0777 -rwxrwxrwx   1 jason jason  177 Sep 20  2016 my.c*
0777 -rwxrwxrwx   1 jason jason 1.9K Feb 12  2012 myftp.c*
0777 -rwxrwxrwx   1 jason jason  42K Feb 20  2011 my_linux_system.php*
0777 -rwxrwxrwx   1 jason jason 1.2K Jan 31  2011 program.c*
0777 -rwxrwxrwx   1 jason jason  471 Aug 30  2009 syscall.c*
0777 -rwxrwxrwx   1 jason jason  349 Mar  1  2011 tank.sh*
0777 -rwxrwxrwx   1 jason jason  313 Jan 19  2011 time.c*
0777 -rwxrwxrwx   1 jason jason 1.2K Mar 11  2011 tiny.asm*
0777 -rwxrwxrwx   1 jason jason  866 Feb 24  2011 utmp.c*
0777 -rwxrwxrwx   1 jason jason 1.8K Mar 11  2011 x11.c*
0777 -rwxrwxrwx   1 jason jason  141 Feb 23  2011 xvid.sh*
0777 -rwxrwxrwx   1 jason jason  136 Feb 17  2011 yadex_15172.c*

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.