Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I cut(1) camelcase words?

Is there an easy way in Bash to split a camelcased word into its constituent words?

For example, I want to split aCertainCamelCasedWord into 'a Certain Camel Cased Word' and be able to select those fields that interest me. This is trivially done with cut(1) when the word separator is the underscore, but how can I do this when the word is camelcased?

like image 818
lindelof Avatar asked Mar 05 '09 14:03

lindelof


People also ask

How do I extract words from a camel case string?

assertThat (findWordsInMixedCase ( "thisIsCamelCaseText" )) .containsExactly ( "this", "Is", "Camel", "Case", "Text" ); Here we see that the words are extracted from a camel case String and come out with their capitalization unchanged. For example, “Is” started with a capital letter in the original text, and is capitalized when extracted.

Are all letters in a CamelCase sequence lowercase?

All letters in the first word are lowercase. For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase. Given a CamelCase sequence represented as a string.

How to split a CamelCase string into strings in Python?

Given a string in camel case, write a Python program to split each word in the camel case string into individual strings. A naive or brute-force approach to split CamelCase string to individual strings is to use for loop. First, use an empty list ‘words’ and append the first letter of ‘str’ to it.

What is uppercase and lowercase camel case?

CamelCase is the sequence of one or more than one words having the following properties: It is a concatenation of one or more words consisting of English letters. All letters in the first word are lowercase. For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase.


1 Answers

sed 's/\([A-Z]\)/ \1/g'

Captures each capital letter and substitutes a leading space with the capture for the whole stream.

$ echo "aCertainCamelCasedWord" | sed 's/\([A-Z]\)/ \1/g'
a Certain Camel Cased Word
like image 156
Judge Maygarden Avatar answered Nov 03 '22 23:11

Judge Maygarden