tr

How To: Convert Text Following Title Case Rules in Bash

此生再无相见时 提交于 2019-12-02 13:42:22
How to convert string to title case while following rules , not just simply capitalizing every first letter of the word? Sample rule: Capitalize all words, with exception to: Lowercase all articles (a, the), prepositions (to, at, in, with), and coordinating conjunctions (and, but, or) Capitalize the first and last word in a title, regardless of part of speech Any easy way to do this in bash? One-liners appreciated. (And just as an additional note, this is to be used in parcellite actions.) $ cat titles.txt purple haze Somebody To Love fire on the mountain THE SONG REMAINS THE SAME Watch the

嵌入式Qt方案中文显示系列:应用程序本地中文显示的实现

 ̄綄美尐妖づ 提交于 2019-12-01 18:58:01
嵌入式Qt应用程序进行中文显示有两种解决方案,一种是直接在代码中使用中文,利用QTextCodec类来实现,另一种是使用qt平台的国际化支持机制,通过语言翻译来实现。第一种方案直接明了,相对来说也简单方便一点,除了编码时麻烦点(来回切换输入法),而第二种方法的优点是具有良好的扩展性,代码中全部使用英文,然后使用中文翻译文件来进行语言翻译,当需要其它语言方案时,只需要添加翻译文件就可以。这里先介绍第一种方案,之后再写第二方案的文章。 方案实现 直接使用中文,利用QTextCodec类来实现中文的显示方案实现通过下面的三个步骤: 中文字体文件的存在:前文提到过字体文件的内容,文泉驿字体库是支持中文的。 应用程序代码中QTextCodec的设置和QFont字体的设置:对整个应用程序来说,一般是放在main函数中进行设置,大概的代码如下: int main(int argc, char *argv[]) { QApplication app(argc,argv); ... QTextCodec* codec = QTextCodec::codecForName("UTF-8"); app.setFont(QFont("wenquanyi",16,75,FALSE,QFont::Unicode)); app.setDefaultCodec(codec); ... return app

How to remove the decorate colors characters in bash output?

北城以北 提交于 2019-12-01 06:34:26
A console program (translate-shell) has an output with colors and uses special decorate characters for this: ^[[22m, ^[[24m, ^[[1m... and so on. I'd like to remove them to get a plain text. I tried with tr -d "^[[22m" and with sed 's/[\^[[22m]//g', but only is removed the number, not the special character ^[ Thanks. tuxdna You have multiple options: https://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed and as -no-ansi as pointed out

Escape status within a string literal as argument of `String#tr`

梦想的初衷 提交于 2019-12-01 03:14:57
问题 There is something mysterious to me about the escape status of a backslash within a single quoted string literal as argument of String#tr . Can you explain the contrast between the three examples below? I particularly do not understand the second one. To avoid complication, I am using 'd' here, which does not change the meaning when escaped in double quotation ( "\d" = "d" ). '\\'.tr('\\', 'x') #=> "x" '\\'.tr('\\d', 'x') #=> "\\" '\\'.tr('\\\d', 'x') #=> "x" 回答1: Escaping in tr The first

Trying to delete non-ASCII characters only [duplicate]

孤者浪人 提交于 2019-11-30 13:42:02
This question already has an answer here: Remove non-ASCII characters from CSV 11 answers I am trying to manipulate a text file and remove non-ASCII characters from the text. I don't want to remove the line. I only want to remove the offending characters. I am trying to get the following expression to work: sed '/[\x80-\xFF]/d' The suggested solutions may fail with specific version of sed, e.g. GNU sed 4.2.1. Using tr : tr -cd '[:print:]' < yourfile.txt This will remove any characters not in [\x20-\x7e] . If you want to keep e.g. line feeds, just add \n : tr -cd '[:print:]\n' < yourfile.txt If

tr command - how to replace the string “\\n” with an actual newline (\\n)

余生长醉 提交于 2019-11-30 10:46:07
I would like to use the tr command to replace all occurrences of the string "\n" with a new line (\n). I tried tr '\\n' '\n' but this just seems to match any '\' and any 'n' Here's how to do it with sed : sed 's/\\n/\n/g' Example usage: To replace all occurrences of \n in a file in-place: sed -i 's/\\n/\n/g' input_filename To replace all occurrences of \n through a pipe, and save into another file cat file1 file2 file3 file4 | sed 's/\\n/\n/g' > output_file 来源: https://stackoverflow.com/questions/13610639/tr-command-how-to-replace-the-string-n-with-an-actual-newline-n

unix tr find and replace

ぐ巨炮叔叔 提交于 2019-11-30 05:18:29
This is the command I'm using on a standard web page I wget from a web site. tr '<' '\n<' < index.html however it giving me newlines, but not adding the left broket in again. e.g. echo "<hello><world>" | tr '<' '\n<' returns (blank line which is fine) hello> world> instead of (blank line or not) <hello> <world> What's wrong? That's because tr only does character-for-character substitution (or deletion). Try sed instead. echo '<hello><world>' | sed -e 's/</\n&/g' Or awk . echo '<hello><world>' | awk '{gsub(/</,"\n<",$0)}1' Or perl . echo '<hello><world>' | perl -pe 's/</\n</g' Or ruby . echo '

unix tr find and replace

不羁的心 提交于 2019-11-29 03:07:49
问题 This is the command I'm using on a standard web page I wget from a web site. tr '<' '\n<' < index.html however it giving me newlines, but not adding the left broket in again. e.g. echo "<hello><world>" | tr '<' '\n<' returns (blank line which is fine) hello> world> instead of (blank line or not) <hello> <world> What's wrong? 回答1: That's because tr only does character-for-character substitution (or deletion). Try sed instead. echo '<hello><world>' | sed -e 's/</\n&/g' Or awk . echo '<hello>

Removing all special characters from a string in Bash

别说谁变了你拦得住时间么 提交于 2019-11-29 01:58:22
I have a lot of text in lowercase, only problem is, that there is a lot of special characters, which I want to remove it all with numbers too. Next command it's not strong enough: tr -cd '[alpha]\n ' In case of éćščž and some others it returns "?" But I want to remove all of them. Is there any stronger command? I use linux mint 4.3.8(1)-release You can use tr to print only the printable characters from a string like below. Just use the below command on your input file. tr -cd "[:print:]\n" < file1 The flag -d is meant to the delete the character sets defined in the arguments on the input

Replace slash in Bash

≯℡__Kan透↙ 提交于 2019-11-29 01:51:37
问题 Let's suppose I have this variable: DATE="04/Jun/2014:15:54:26" . Therein I need to replace / with \/ in order to get the string: "04\/Jun\/2014:15:54:26" . I tried tr as follows: echo "04\Jun\2014:15:54:26" | tr '\' '\\/' But this results in: "04\Jun\2014:15:54:26" . It does not satisfy me. Can anyone help? 回答1: No need to use an echo + a pipe + sed. A simple substitution variable is enough and faster: echo ${DATE//\//\\/} #> 04\/Jun\/2014:15:54:26 回答2: Use SED for substitutions: sed 's#/#\\