- cat htmlist | perl -nle 'print$1 if m/^(.*)_public_access.log_stats.html/' > complist.txt
- list all the files but cut the last part "_public_access.log_stats.html"
- Prints part of the command output, wc -l
would print ($1, $2) if you want both to be printed use awk '{print $1,$2}' - Reference
- cat file_name | awk 'NR > 11'
- Print lines after 11 in a file -
Reference- perl -ne 'print if 1..100' FILE_NAME
- Print lines in a range , if you specify the end as 0 (zero) it will print all the lines starting from the begin range provided till the end of the file
- find . -name "*.log" -print | awk '{print "rm " $1}' | sh
- delete all find under all sub folders in a folder at once in one line. The cool thing here is piping to sh, which is same as piping it to a sh file and running it, all in one line
- ls *html | perl -nle 'print $2 if m/^(.*)_i001_(.*)_reduced_(.*).html/' | sort | uniq
- list all files with the matching regular expression but only the part of the file name you need dont repeat if its already printed. ( sort is a unix command and uniq is also a unix command )
- grep -f file-1.txt file-2.txt | uniq
- this cmd will list all lines which are identical in 2 files. This is different than diff in the sense that it is not location sensitive, hence very useful for listing common contents/lines in files regardless of location.
- sed 's/$/SUFFIX_TXT/' original_file.txt > new_file.txt
- this one-line cmd will add suffix specified "SUFFIX_TXT" at the end of each line in the original_file.txt and pipe it to a new file
- perl -pi -e "s/host=\'([^\']*)\'/host=\'host.com\'/g" *.xml
- This one-line cmd will go through all the XML files in a folder ( in this case 270, and apply the regular expression to all of them.
- for i in *.jar; do echo $i; jar tvf $i | grep com.linkedin.geo; done;
- This online command will do jar -tvf on all jars on all jars in the folders and the sub-folders, you can also do with with awk, but awk cant do sub-folder as we use grep there
Labels: awk, one-liners, perl, sed
# posted by Hari @ 1:23 PM