|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
How do I extract all words which use a certain character from a text file ?
I want to extract all words which have a character (ie. $) from a text. Is there a simple command in Terminal or even text editors ? Thanks!
|
|
|
|
0
|
|
|
#2 |
|
Most text editors have a "find" function where you can search for anything containing any number of letters.
__________________
Con + Cat |
|
|
|
0
|
|
|
#3 |
|
Yes but I want to extract all of the different words which include that character. When the file is long, is hard to copy-paste all words one by one. There must be a Unix command which I'm searching now, before anyone post an answer.
|
|
|
|
0
|
|
|
#4 |
|
Assuming you are in the correct directory containing the file, the file is called file.txt and you want the list of words in output.txt then this will do it (without correcting for caps/non-caps). We are searching for c. If you want to search for $ you might well have to escape it
Code:
cat file.txt | tr -d '[:punct:]' | tr ' ' '\n' | grep c | sort | uniq > output.txt
__________________
Sponsor me to cycle 100Km round London in the dark |
|
|
|
0
|
|
|
#5 |
|
Thank you so much, you saved me good amount of searching. I finally had to replace the special character to do the task quicker. I tried to escape it with single and double quotes but it didn't work.
|
|
|
|
0
|
|
|
#6 |
|
What is the special character? $ or something else?
__________________
Sponsor me to cycle 100Km round London in the dark |
|
|
|
0
|
|
|
#7 | |
|
Quote:
B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme |
||
|
|
0
|
|
|
#8 |
|
|
0
|
|
|
#9 |
|
What character are you wanting to extract the words containing?
__________________
Sponsor me to cycle 100Km round London in the dark |
|
|
|
0
|
|
|
#10 |
|
This time I was looking for @ and $. I assign these characters to tasks, its nothing to do with their usual connotation.
|
|
|
|
0
|
|
|
#11 |
|
Convert each word to a line, and use sed: http://unix.stackexchange.com/questi...r-standard-sed
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 12:49 PM.







Linear Mode
