tr

How do I split “abcd efgh” into “abcd” and “efgh”?

回眸只為那壹抹淺笑 提交于 2019-12-07 04:53:27
This is really self explanatory. I'm working in a bash shell and I'm really new to shell scripting. I've found a lot of information about using tr and sed but all the examples I have found so far are removing delimiters and new lines. I really want to do the opposite of that. I want to be able to separate based on a blank space. I have a string like "abcd efgh" and I need it to be "abcd" "efgh" (all without quotes, just to show groupings). I'm sure this is much simpler than I'm making it, but I'm very confused. Updated Question: I have a column of PIDs that I have put into an array, but each

Transliteration script for linux shell

邮差的信 提交于 2019-12-07 04:38:00
问题 I have multiple .txt files containing text in an alphabet; I want to transliterate the text into an other alphabet; some characters of alphabet1 are 1:1 with those of alphabet2 (i.e. a becomes e ), whereas others are 1:2 (i.e. x becomes ch ). I would like to do this using a simple script for the Linux shell. With tr or sed I can convert 1:1 characters: sed -f y/abcdefghijklmnopqrstuvwxyz/nopqrstuvwxyzabcdefghijklm/ a will become n , b will become o et cetera (a Caesar's cipher, I think) But

Remove matching and previous line

此生再无相见时 提交于 2019-12-06 11:59:15
I need to remove a line containing "not a dynamic executable" and a previous line from a stream using grep, awk, sed or something other. My current working solution would be to tr the entire stream to strip off newlines then replace the newline preceding my match with something else using sed then use tr to add the newlines back in and then use grep -v. I'm somewhat weary of artifacts with this approach, but I don't see how else I can to it at the moment: tr '\n' '|' | sed 's/|\tnot a dynamic executable/__MY_REMOVE/g' | tr '|' '\n' EDIT: Input is a list of mixed files piped to xargs ldd,

How to replace one character with two characters using tr

喜夏-厌秋 提交于 2019-12-05 12:05:32
问题 Can tr replace one character with two characters? I am trying to replace "~" with "~\n" but the output does not produce the newline. $ echo "asdlksad ~ adlkajsd ~ 12345" | tr "~" "~\n" asdlksad ~ adlkajsd ~ 12345 回答1: No, tr is specifically intended to replace single characters by single characters (or, depending on command-line options, to delete characters or replace runs of a single character by one occurrence.). sed is probably the best tool for this particular job: $ echo "asdlksad ~

Transliteration script for linux shell

巧了我就是萌 提交于 2019-12-05 10:14:31
I have multiple .txt files containing text in an alphabet; I want to transliterate the text into an other alphabet; some characters of alphabet1 are 1:1 with those of alphabet2 (i.e. a becomes e ), whereas others are 1:2 (i.e. x becomes ch ). I would like to do this using a simple script for the Linux shell. With tr or sed I can convert 1:1 characters: sed -f y/abcdefghijklmnopqrstuvwxyz/nopqrstuvwxyzabcdefghijklm/ a will become n , b will become o et cetera (a Caesar's cipher, I think) But how can I deal with 1:2 characters? Not an answer, just to show a briefer, idiomatic way to populate the

What is the most efficient case-insensitive grep usage?

蹲街弑〆低调 提交于 2019-12-04 15:00:45
问题 My objective is to match email addresses that belong to the Yahoo! family of domains. In *nix systems (I will be using Ubuntu), what are the benefits and drawbacks to any one of these methods for matching the pattern? And if there is another, more elegant solution that I haven't been capable of imagining, please share. Here they are: Use grep with option -i : grep -Ei "@(yahoo|(y|rocket)mail|geocities)\.com" Translate characters to all upper case or lower case then grep : tr [:upper:] [:lower

What is the most efficient case-insensitive grep usage?

痴心易碎 提交于 2019-12-03 10:22:27
My objective is to match email addresses that belong to the Yahoo! family of domains. In *nix systems (I will be using Ubuntu), what are the benefits and drawbacks to any one of these methods for matching the pattern? And if there is another, more elegant solution that I haven't been capable of imagining, please share. Here they are: Use grep with option -i : grep -Ei "@(yahoo|(y|rocket)mail|geocities)\.com" Translate characters to all upper case or lower case then grep : tr [:upper:] [:lower:] < /path/to/file.txt | grep -E "@(yahoo|(y|rocket)mail|geocities)\.com" Include a character set for

Removing trailing / starting newlines with sed, awk, tr, and friends

孤街醉人 提交于 2019-12-03 02:37:18
问题 I would like to remove all of the empty lines from a file, but only when they are at the end/start of a file (that is, if there are no non-empty lines before them, at the start; and if there are no non-empty lines after them, at the end.) Is this possible outside of a fully-featured scripting language like Perl or Ruby? I’d prefer to do this with sed or awk if possible. Basically, any light-weight and widely available UNIX-y tool would be fine, especially one I can learn more about quickly

How To: Convert Text Following Title Case Rules in Bash

时间秒杀一切 提交于 2019-12-02 23:49:37
问题 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.)

Removing trailing / starting newlines with sed, awk, tr, and friends

╄→尐↘猪︶ㄣ 提交于 2019-12-02 16:12:33
I would like to remove all of the empty lines from a file, but only when they are at the end/start of a file (that is, if there are no non-empty lines before them, at the start; and if there are no non-empty lines after them, at the end.) Is this possible outside of a fully-featured scripting language like Perl or Ruby? I’d prefer to do this with sed or awk if possible. Basically, any light-weight and widely available UNIX-y tool would be fine, especially one I can learn more about quickly (Perl, thus, not included.) From Useful one-line scripts for sed : # Delete all leading blank lines at