tr

How can I remove the stop words from sentence using shell script?

浪子不回头ぞ 提交于 2021-01-07 06:57:50
问题 I'm trying to remove stop words from sentences in file? Stop Word which I mean : [I, a, an, as, at, the, by, in, for, of, on, that] I have these sentences in file my_text.txt : One of the primary goals in the design of the Unix system was to create an environment that promoted efficient program Then I want to remove stop word form the sentence above I used this script : array=( I a an as at the by in for of on that ) for i in "${array[@]}" do cat $p | sed -e 's/\<$i\>//g' done < my_text.txt

Bash process substitution behaves differently than named pipe?

房东的猫 提交于 2020-06-16 16:58:47
问题 Kind of a follow up to this question. I use bash process substitution expecting to see 5 lines of output (corresponding to 5s timeout) however I only see 4 lines: timeout 5s dd if=/dev/random | pv -fr > /dev/null 2> >(tr '\r' '\n' >&2) [5.42kiB/s] [1.89kiB/s] [5.36kiB/s] [2.41kiB/s] However if I place a named pipe in the middle I do get the 5 lines as expected. First shell: mkfifo testfifo cat testfifo | tr '\r' '\n' >&2 Second shell: timeout 5s dd if=/dev/random | pv -fr > /dev/null 2>

Using tr to replace newline with space [duplicate]

假装没事ソ 提交于 2020-02-26 04:53:26
问题 This question already has answers here : How can I replace a newline (\n) using sed? (41 answers) Closed 4 years ago . Have output from sed : http://sitename.com/galleries/83450 72-profile Those two strings should be merged into one and separated with space like: http://sitename.com/galleries/83450 72-profile Two strings are pipelined to tr in order to replace newline with space: tr '\n' ' ' And it's not working, the result is the same as input. Indicating space with ASCII code '\032' results

Unix tr command to convert lower case to upper AND upper to lower case

血红的双手。 提交于 2020-01-23 08:25:21
问题 So I was searching around and using the command tr you can convert from lower case to upper case and vice versa. But is there a way to do this both at once? So: $ tr '[:upper:]' '[:lower:]' or $ tr A-Z a-z will turn: "Hello World ABC" to "hello world abc" but I want it to do: "hELLO wORLD abc" Please help! =) 回答1: This will do what you are looking for: tr '[:upper:][:lower:]' '[:lower:][:upper:]' 回答2: I think tr '[a-zA-Z]' '[A-Za-z]' is more straight forward, and easier to remember. 回答3: You

Trying to delete non-ASCII characters only [duplicate]

主宰稳场 提交于 2020-01-21 03:11:06
问题 This question already has answers here : Remove non-ASCII characters from CSV (11 answers) Closed 6 years ago . 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' 回答1: 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

Translating character from a list to my file

女生的网名这么多〃 提交于 2020-01-06 14:10:28
问题 I have lots of files that look like this: 136 155 223 783 344 455 230 . . . And another file like this (the dictionary): rs6427315 230 rs1171564 455 rs1609666 344 rs728917 155 rs728918 223 rs11264495 783 rs11805559 136 . . . . . . And I want a new file that looks like this, that is reading the characters from my first file and substituting them with the match in column 1 from the other file: rs11805559 rs728917 rs728918 rs11264495 rs1609666 rs1609666 rs1171564 rs6427315 Thanks in advance 回答1:

Translating character from a list to my file

為{幸葍}努か 提交于 2020-01-06 14:10:12
问题 I have lots of files that look like this: 136 155 223 783 344 455 230 . . . And another file like this (the dictionary): rs6427315 230 rs1171564 455 rs1609666 344 rs728917 155 rs728918 223 rs11264495 783 rs11805559 136 . . . . . . And I want a new file that looks like this, that is reading the characters from my first file and substituting them with the match in column 1 from the other file: rs11805559 rs728917 rs728918 rs11264495 rs1609666 rs1609666 rs1171564 rs6427315 Thanks in advance 回答1:

How to remove the decorate colors characters in bash output?

若如初见. 提交于 2019-12-30 10:07:08
问题 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. 回答1: You have multiple options: https://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output http://www.commandlinefu

Unable to remove carriage returns and line feeds in columns enclosed in double quotes [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-25 11:25:08
问题 This question already has an answer here : What's the most robust way to efficiently parse CSV using awk? (1 answer) Closed 2 years ago . I want to remove any non printable new line characters in the column data. I have enclosed all the columns with double quotes to delete the new line characters present in the column easily and to ignore the record delimiter after each end of line. Say,I have 4 columns seperated by comma and enclosed by quotes in a text file. I'm trying to remove \n and \r

Cygwin and tr settings

你说的曾经没有我的故事 提交于 2019-12-24 13:50:32
问题 I use a Unix utility tr via Cygwin. I want to replace the non-alphabetical characters for '\ n', but tr also recognize accented characters as non-alphabetic (ěščřžýáíé -> \ n). Can I change this setting? Thanks. 回答1: This should do it tr -c '[:cntrl:][:print:]' '\n' Depending on locale you might need to LANG= tr -c '[:cntrl:][:print:]' '\n' Or this tr -c $'\x01-\x7e' '\n' 来源: https://stackoverflow.com/questions/23471322/cygwin-and-tr-settings