Showing posts with label Sed. Show all posts
Showing posts with label Sed. Show all posts

Friday, 14 June 2013

Tips and Tricks

Make ps more readable and put on separate lines
 ps -ef | grep java | tr " " "\n"  
Show hidden files with du
 du -sk .[!.]* *| sort -n  
Show just hidden files with du
 du -sh .[a-zA-Z]*  
Trim last character in vi
 :%s/.$//g  
With sed
 sed '$s/.$//'  
Awk, print all on one line with a comma seperating
 awk '{ printf "%s,", $1 }'  
Find command with regex
 find . -name \*[Ii]nstall\*[Ll]og\*  
Remove all blank lines with awk
 awk '/./' abc.txt  
Show octal permissions when doing an ls
for file in `ls`; do echo -n `stat -c %a $file`; echo -n " "; ls -ltd $file; done  
Using awk with a field seperator
 awk 'BEGIN { FS = "," } ; { print $1 }'  
Remove HTML tags from a file
 sed "s/<[^>]\+>//g" file  

Awk print from third column to the end
 awk '{ print substr($0, index($0,$3)) }'  

Thursday, 30 May 2013

Get a list of files that exist on a website via curl and strip out HTML code

The following can be used to display a list of .csv.gz files that exist on a website and strips out all HTML code:-
 curl --silent http://www.theurl.com/thefiles/ | egrep -o "<a href=[^>]*>*.csv.gz"
 | sed 's/<a href=\"\([^"]*\).*/\1/g'  

The --silent flag in curl supresses the progress information and any error messages