# This script creates screen sessions, ssh's to machines and executes code on these machines. Sending multiple commands to screen session on different machines Matches a group of numbers in the beginning of a line One-Liner: Replace specific space but also copy a group of matches One-Liner: How to sort a file by a columnĬolumns are separated by a space, we sort numerically (-n) and we sort by the 10'th column (-k10)īash does the job here, no perl needed ) Perl -ne = split("\t", $_) print "$F" ' columnFileWithTabs.txt > justSecondColumn.txt Print only the second column of the data when using tabular as a separator Perl -pne 'tr///' sentences.txt | perl -ne 'print join("\n", split(/ /,$_)) print("\n")' | sort | uniq -c | sort -n One-Liner Combination: Combine lower-casing with word counting and sorting Perl -pne 'tr///' textWithUpperCase.txt > textwithoutuppercase.txt Or in other words, delete every character that is not a letter, white space or line end (replace with nothing)perl -pne 's/*//g' text_withSpecial.txt > text_lettersOnly.txt One-Liner: Return all unique words in a text document (divided by spaces), sorted by their counts (how often they appear)Īssuming no punctuation marks:perl -ne 'print join(" \n", split(/ \s+/,$_)) print(" \n")' documents.txt > wordsOnePerLine.txtĬat wordsOnePerLine.txt | sort | uniq -c | sort -n > wordCountsSorted.txt Since there's no screen command that would kill all screen sessions regardless of what they're doing, here's a perl one-liner that really kills ALL screen sessions without remorse.screen -ls | perl -ne '/(\d+)\./ print $1' | xargs -l kill -9 One-Liner: Kill all screen sessions (no remorse) Go through file, split line at each space and print words one per line.perl -ne 'print join("\n", split(/ /,$_)) print("\n")' someText.txt > wordsPerLine.txt Go through file and only print words that do not have any uppercase letters.perl -ne 'print unless m//' allWords.txt > allWordsOnlyLowercase.txt One-Liner: Print only non-uppercase letters ) with pattern2perl -p -i.bak -w -e 's/pattern1/pattern2/g' inputFile Replace all occurrences of pattern1 (e.g. One-Liner: Replace a pattern with another one inside the file with backup One-Liner: Print all columns except the firstĬut -d" " -f 1 -complement filename > filename. One-Liner: Print only some columns of a fileĬolumns separated by a spacecut fileWithLotsOfColumns.txt -d" " -f 1,2,3,4 > fileWithOnlyFirst4Cols.txt One-Liner: Add newline to end of each lineĪppend a new line to each lineperl -pe 's// \n/' > One-Liner: Add string to beginning of each lineĪdds string to each line, followed by tabperl -pe 's/(.*)/string \t$1/' inFile > outFile
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |