Bash script: split word on each letter
How can I split a word's letters, with each letter in a separate line?
For example, given "StackOver"
I would like to see
S
t
a
c
k
O
v
e
r
I'm new to bash so I have no clue where to start.
command-line split words
add a comment |
How can I split a word's letters, with each letter in a separate line?
For example, given "StackOver"
I would like to see
S
t
a
c
k
O
v
e
r
I'm new to bash so I have no clue where to start.
command-line split words
add a comment |
How can I split a word's letters, with each letter in a separate line?
For example, given "StackOver"
I would like to see
S
t
a
c
k
O
v
e
r
I'm new to bash so I have no clue where to start.
command-line split words
How can I split a word's letters, with each letter in a separate line?
For example, given "StackOver"
I would like to see
S
t
a
c
k
O
v
e
r
I'm new to bash so I have no clue where to start.
command-line split words
command-line split words
edited Jul 25 '16 at 12:30
Jeff Schaller
41.4k1056131
41.4k1056131
asked Jan 4 '16 at 23:41
Sijaan HallakSijaan Hallak
122111
122111
add a comment |
add a comment |
15 Answers
15
active
oldest
votes
I would use grep:
$ grep -o . <<<"StackOver"
S
t
a
c
k
O
v
e
r
or sed:
$ sed 's/./&n/g' <<<"StackOver"
S
t
a
c
k
O
v
e
r
And if empty space at the end is an issue:
sed 's/B/&n/g' <<<"StackOver"
All of that assuming GNU/Linux.
grep -o . <<< ¿¿¿ .. -o searches for the PATTERN provided right? and what it does here in your command?
– Sijaan Hallak
Jan 5 '16 at 0:06
1
@jimmij I cant find any help on what <<< really does! any help?
– Sijaan Hallak
Jan 5 '16 at 10:50
3
@SijaanHallak This is so calledHere string, grosso modo equivalent ofecho foo | ...just less typing. See tldp.org/LDP/abs/html/x17837.html
– jimmij
Jan 5 '16 at 11:02
1
@SijaanHallak change.toB(doesn't match on word boundary).
– jimmij
Jan 5 '16 at 17:40
1
@SijaanHallak - you can drop the secondsedlike:sed -et -e's/./n&/g;//D'
– mikeserv
Jan 6 '16 at 6:30
|
show 8 more comments
You may want to break on grapheme clusters instead of characters if the intent is to print text vertically. For instance with a e with an acute accent:
With grapheme clusters (
ewith its acute accent would be one grapheme cluster):
$ perl -CLAS -le 'for (@ARGV) {print for /X/g}' $'Steu301phane'
S
t
é
p
h
a
n
e
(or
grep -Po 'X'with GNU grep built with PCRE support)
With characters (here with GNU
grep):
$ printf '%sn' $'Steu301phane' | grep -o .
S
t
e
p
h
a
n
e
foldis meant to break on characters, but GNUfolddoesn't support multi-byte characters, so it breaks on bytes instead:
$ printf '%sn' $'Steu301phane' | fold -w 1
S
t
e
�
�
p
h
a
n
e
On StackOver which only consists of ASCII characters (so one byte per character, one character per grapheme cluster), all three would give the same result.
I'm surprisedgrep -Podoesn't do what one would expect (likegrep -Pdoes).
– jimmij
Jan 5 '16 at 0:19
@jimmij, what do you mean?grep -Po .finds characters (and a combining acute accent following a newline character is invalid), andgrep -Po 'X'finds graphem clusters for me. You may need a recent version of grep and/or PCRE for it to work properly (or trygrep -Po '(*UTF8)X')
– Stéphane Chazelas
Jan 5 '16 at 0:23
2
@SijaanHallak These might be helpful: joelonsoftware.com/articles/Unicode.html, eev.ee/blog/2015/09/12/dark-corners-of-unicode
– jpmc26
Jan 5 '16 at 21:55
add a comment |
If you have perl6 in your box:
$ perl6 -e 'for @*ARGS -> $w { .say for $w.comb }' 'cường'
c
ư
ờ
n
g
work regardless of your locale.
add a comment |
With many awk versions
awk -F '' -v OFS='n' '{$1=$1};1' <<<'StackOver'
Great! But on my version of nAWK ("One True AWK") that doesn't work. However this does the trick:awk -v FS='' -v OFS='n' '{$1=$1};1'(wondering if that's more portable since-F ''might yield the ERE://)
– eruve
Feb 4 at 6:48
add a comment |
The below will be generic:
$ awk -F ''
'BEGIN { RS = ""; OFS = "n"} {for (i=1;i<=NF;i++) $i = $i; print }' <file_name>
add a comment |
echo StackOver | sed -e 's/./&n/g'
S
t
a
c
k
O
v
e
r
This won't help as it prints a new line at the end
– Sijaan Hallak
Jan 5 '16 at 10:56
add a comment |
Since you specifically asked for an answer in bash, here's a way to do it in pure bash:
while read -rn1; do echo "$REPLY" ; done <<< "StackOver"
Note that this will catch the newline at the end of the "here document". If you want to avoid that, but still iterate over the characters with a bash loop, use printf to avoid the newline.
printf StackOver | while read -rn1; do echo "$REPLY" ; done
add a comment |
Also Python 2 can be used from the command line:
python <<< "for x in 'StackOver':
print x"
or:
echo "for x in 'StackOver':
print x" | python
or (as commented by 1_CR) with Python 3:
python3 -c "print(*'StackOver',sep='n')"
add a comment |
You can use the fold (1) command. It is more efficient than grep and sed.
$ time grep -o . <bigfile >/dev/null
real 0m3.868s
user 0m3.784s
sys 0m0.056s
$ time fold -b1 <bigfile >/dev/null
real 0m0.555s
user 0m0.528s
sys 0m0.016s
$
One significant difference is that fold will reproduce empty lines in the output:
$ grep -o . <(printf "AnBnnCnnnDn")
A
B
C
D
$ fold -b1 <(printf "AnBnnCnnnDn")
A
B
C
D
$
add a comment |
You can handle multibyte characters like:
<input
dd cbs=1 obs=2 conv=unblock |
sed -e:c -e '/^.*$/!N;s/n//;tc'
Which can be pretty handy when you're working with live input because there's no buffering there and a character is printed as soon it is whole.
NP, should we add a note about the locale?
– cuonglm
Jan 5 '16 at 9:35
Does not work for combining characters like Stéphane Chazelas answer, but with proper normalization this should not matter.
– kay
Jan 5 '16 at 13:06
@Kay - it's works for combining characters if you want it to - that's whatsedscripts are for. i'm not likely to write one right about now - im pretty sleepy. it's really useful, though, when reading a terminal.
– mikeserv
Jan 5 '16 at 14:30
@cuonglm - if you like. it should just work for the locale, given a sane libc, though.
– mikeserv
Jan 5 '16 at 14:33
Note thatddwill break multibyte characters, so the output will not be text anymore so the behaviour of sed will be unspecified as per POSIX.
– Stéphane Chazelas
Jan 5 '16 at 22:09
|
show 2 more comments
You may use word boundaries also..
$ perl -pe 's/(?<=.)(B|b)(?=.)/n/g' <<< "StackOver"
S
t
a
c
k
O
v
e
r
add a comment |
In bash:
This works with any text and with only bash internals (no external utility called), so, should be fast on very short strings.
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
(set -- "${BASH_REMATCH[@]:1}"; IFS=$'n'; echo "$*")
Output:
S
t
é
p
h
a
n
e
á
à
é
è
ë
ê
ế
e
If it is ok to change IFS and to change the positional parameters, you can also avoid the sub-shell call:
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
set -- "${BASH_REMATCH[@]:1}"
IFS=$'n'
echo "$*"
add a comment |
s=stackoverflow;
$ time echo $s | fold -w1
s
t
a
c
k
o
v
e
r
real 0m0.014s
user 0m0.000s
sys 0m0.004s
updates
here is the hacky|fastest|pureBashBased way !
$ time eval eval printf '%s\\n' \${s:{0..$((${#s}-1))}:1}
s
t
a
c
k
o
v
e
r
real 0m0.001s
user 0m0.000s
sys 0m0.000s
for more awesomeness
function foldh ()
{
if (($#)); then
local s="$@";
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
function foldv ()
{
if (($#)); then
local s="$@";
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
Will this ever give different results tofold -b1?
– JigglyNaga
Jul 25 '16 at 12:10
since each byte have a width=1 the result will be the same !
– Jonas
Jul 25 '16 at 12:30
1
So how is this not a duplicate of the earlier answer?
– JigglyNaga
Jul 25 '16 at 13:17
because it shows tha same cmd with different argyment , and that is nice to know .
– Jonas
Jul 25 '16 at 13:45
add a comment |
read -a var <<< $(echo "$yourWordhere" | grep -o "." | tr 'n' ' ')
this will split your word and store it in array var.
add a comment |
for x in $(echo "$yourWordhere" | grep -o '.')
do
code to perform operation on individual character $x of your word
done
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f253279%2fbash-script-split-word-on-each-letter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
15 Answers
15
active
oldest
votes
15 Answers
15
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would use grep:
$ grep -o . <<<"StackOver"
S
t
a
c
k
O
v
e
r
or sed:
$ sed 's/./&n/g' <<<"StackOver"
S
t
a
c
k
O
v
e
r
And if empty space at the end is an issue:
sed 's/B/&n/g' <<<"StackOver"
All of that assuming GNU/Linux.
grep -o . <<< ¿¿¿ .. -o searches for the PATTERN provided right? and what it does here in your command?
– Sijaan Hallak
Jan 5 '16 at 0:06
1
@jimmij I cant find any help on what <<< really does! any help?
– Sijaan Hallak
Jan 5 '16 at 10:50
3
@SijaanHallak This is so calledHere string, grosso modo equivalent ofecho foo | ...just less typing. See tldp.org/LDP/abs/html/x17837.html
– jimmij
Jan 5 '16 at 11:02
1
@SijaanHallak change.toB(doesn't match on word boundary).
– jimmij
Jan 5 '16 at 17:40
1
@SijaanHallak - you can drop the secondsedlike:sed -et -e's/./n&/g;//D'
– mikeserv
Jan 6 '16 at 6:30
|
show 8 more comments
I would use grep:
$ grep -o . <<<"StackOver"
S
t
a
c
k
O
v
e
r
or sed:
$ sed 's/./&n/g' <<<"StackOver"
S
t
a
c
k
O
v
e
r
And if empty space at the end is an issue:
sed 's/B/&n/g' <<<"StackOver"
All of that assuming GNU/Linux.
grep -o . <<< ¿¿¿ .. -o searches for the PATTERN provided right? and what it does here in your command?
– Sijaan Hallak
Jan 5 '16 at 0:06
1
@jimmij I cant find any help on what <<< really does! any help?
– Sijaan Hallak
Jan 5 '16 at 10:50
3
@SijaanHallak This is so calledHere string, grosso modo equivalent ofecho foo | ...just less typing. See tldp.org/LDP/abs/html/x17837.html
– jimmij
Jan 5 '16 at 11:02
1
@SijaanHallak change.toB(doesn't match on word boundary).
– jimmij
Jan 5 '16 at 17:40
1
@SijaanHallak - you can drop the secondsedlike:sed -et -e's/./n&/g;//D'
– mikeserv
Jan 6 '16 at 6:30
|
show 8 more comments
I would use grep:
$ grep -o . <<<"StackOver"
S
t
a
c
k
O
v
e
r
or sed:
$ sed 's/./&n/g' <<<"StackOver"
S
t
a
c
k
O
v
e
r
And if empty space at the end is an issue:
sed 's/B/&n/g' <<<"StackOver"
All of that assuming GNU/Linux.
I would use grep:
$ grep -o . <<<"StackOver"
S
t
a
c
k
O
v
e
r
or sed:
$ sed 's/./&n/g' <<<"StackOver"
S
t
a
c
k
O
v
e
r
And if empty space at the end is an issue:
sed 's/B/&n/g' <<<"StackOver"
All of that assuming GNU/Linux.
edited Jan 5 '16 at 22:07
answered Jan 4 '16 at 23:49
jimmijjimmij
31.4k872108
31.4k872108
grep -o . <<< ¿¿¿ .. -o searches for the PATTERN provided right? and what it does here in your command?
– Sijaan Hallak
Jan 5 '16 at 0:06
1
@jimmij I cant find any help on what <<< really does! any help?
– Sijaan Hallak
Jan 5 '16 at 10:50
3
@SijaanHallak This is so calledHere string, grosso modo equivalent ofecho foo | ...just less typing. See tldp.org/LDP/abs/html/x17837.html
– jimmij
Jan 5 '16 at 11:02
1
@SijaanHallak change.toB(doesn't match on word boundary).
– jimmij
Jan 5 '16 at 17:40
1
@SijaanHallak - you can drop the secondsedlike:sed -et -e's/./n&/g;//D'
– mikeserv
Jan 6 '16 at 6:30
|
show 8 more comments
grep -o . <<< ¿¿¿ .. -o searches for the PATTERN provided right? and what it does here in your command?
– Sijaan Hallak
Jan 5 '16 at 0:06
1
@jimmij I cant find any help on what <<< really does! any help?
– Sijaan Hallak
Jan 5 '16 at 10:50
3
@SijaanHallak This is so calledHere string, grosso modo equivalent ofecho foo | ...just less typing. See tldp.org/LDP/abs/html/x17837.html
– jimmij
Jan 5 '16 at 11:02
1
@SijaanHallak change.toB(doesn't match on word boundary).
– jimmij
Jan 5 '16 at 17:40
1
@SijaanHallak - you can drop the secondsedlike:sed -et -e's/./n&/g;//D'
– mikeserv
Jan 6 '16 at 6:30
grep -o . <<< ¿¿¿ .. -o searches for the PATTERN provided right? and what it does here in your command?
– Sijaan Hallak
Jan 5 '16 at 0:06
grep -o . <<< ¿¿¿ .. -o searches for the PATTERN provided right? and what it does here in your command?
– Sijaan Hallak
Jan 5 '16 at 0:06
1
1
@jimmij I cant find any help on what <<< really does! any help?
– Sijaan Hallak
Jan 5 '16 at 10:50
@jimmij I cant find any help on what <<< really does! any help?
– Sijaan Hallak
Jan 5 '16 at 10:50
3
3
@SijaanHallak This is so called
Here string, grosso modo equivalent of echo foo | ... just less typing. See tldp.org/LDP/abs/html/x17837.html– jimmij
Jan 5 '16 at 11:02
@SijaanHallak This is so called
Here string, grosso modo equivalent of echo foo | ... just less typing. See tldp.org/LDP/abs/html/x17837.html– jimmij
Jan 5 '16 at 11:02
1
1
@SijaanHallak change
. to B (doesn't match on word boundary).– jimmij
Jan 5 '16 at 17:40
@SijaanHallak change
. to B (doesn't match on word boundary).– jimmij
Jan 5 '16 at 17:40
1
1
@SijaanHallak - you can drop the second
sed like: sed -et -e's/./n&/g;//D'– mikeserv
Jan 6 '16 at 6:30
@SijaanHallak - you can drop the second
sed like: sed -et -e's/./n&/g;//D'– mikeserv
Jan 6 '16 at 6:30
|
show 8 more comments
You may want to break on grapheme clusters instead of characters if the intent is to print text vertically. For instance with a e with an acute accent:
With grapheme clusters (
ewith its acute accent would be one grapheme cluster):
$ perl -CLAS -le 'for (@ARGV) {print for /X/g}' $'Steu301phane'
S
t
é
p
h
a
n
e
(or
grep -Po 'X'with GNU grep built with PCRE support)
With characters (here with GNU
grep):
$ printf '%sn' $'Steu301phane' | grep -o .
S
t
e
p
h
a
n
e
foldis meant to break on characters, but GNUfolddoesn't support multi-byte characters, so it breaks on bytes instead:
$ printf '%sn' $'Steu301phane' | fold -w 1
S
t
e
�
�
p
h
a
n
e
On StackOver which only consists of ASCII characters (so one byte per character, one character per grapheme cluster), all three would give the same result.
I'm surprisedgrep -Podoesn't do what one would expect (likegrep -Pdoes).
– jimmij
Jan 5 '16 at 0:19
@jimmij, what do you mean?grep -Po .finds characters (and a combining acute accent following a newline character is invalid), andgrep -Po 'X'finds graphem clusters for me. You may need a recent version of grep and/or PCRE for it to work properly (or trygrep -Po '(*UTF8)X')
– Stéphane Chazelas
Jan 5 '16 at 0:23
2
@SijaanHallak These might be helpful: joelonsoftware.com/articles/Unicode.html, eev.ee/blog/2015/09/12/dark-corners-of-unicode
– jpmc26
Jan 5 '16 at 21:55
add a comment |
You may want to break on grapheme clusters instead of characters if the intent is to print text vertically. For instance with a e with an acute accent:
With grapheme clusters (
ewith its acute accent would be one grapheme cluster):
$ perl -CLAS -le 'for (@ARGV) {print for /X/g}' $'Steu301phane'
S
t
é
p
h
a
n
e
(or
grep -Po 'X'with GNU grep built with PCRE support)
With characters (here with GNU
grep):
$ printf '%sn' $'Steu301phane' | grep -o .
S
t
e
p
h
a
n
e
foldis meant to break on characters, but GNUfolddoesn't support multi-byte characters, so it breaks on bytes instead:
$ printf '%sn' $'Steu301phane' | fold -w 1
S
t
e
�
�
p
h
a
n
e
On StackOver which only consists of ASCII characters (so one byte per character, one character per grapheme cluster), all three would give the same result.
I'm surprisedgrep -Podoesn't do what one would expect (likegrep -Pdoes).
– jimmij
Jan 5 '16 at 0:19
@jimmij, what do you mean?grep -Po .finds characters (and a combining acute accent following a newline character is invalid), andgrep -Po 'X'finds graphem clusters for me. You may need a recent version of grep and/or PCRE for it to work properly (or trygrep -Po '(*UTF8)X')
– Stéphane Chazelas
Jan 5 '16 at 0:23
2
@SijaanHallak These might be helpful: joelonsoftware.com/articles/Unicode.html, eev.ee/blog/2015/09/12/dark-corners-of-unicode
– jpmc26
Jan 5 '16 at 21:55
add a comment |
You may want to break on grapheme clusters instead of characters if the intent is to print text vertically. For instance with a e with an acute accent:
With grapheme clusters (
ewith its acute accent would be one grapheme cluster):
$ perl -CLAS -le 'for (@ARGV) {print for /X/g}' $'Steu301phane'
S
t
é
p
h
a
n
e
(or
grep -Po 'X'with GNU grep built with PCRE support)
With characters (here with GNU
grep):
$ printf '%sn' $'Steu301phane' | grep -o .
S
t
e
p
h
a
n
e
foldis meant to break on characters, but GNUfolddoesn't support multi-byte characters, so it breaks on bytes instead:
$ printf '%sn' $'Steu301phane' | fold -w 1
S
t
e
�
�
p
h
a
n
e
On StackOver which only consists of ASCII characters (so one byte per character, one character per grapheme cluster), all three would give the same result.
You may want to break on grapheme clusters instead of characters if the intent is to print text vertically. For instance with a e with an acute accent:
With grapheme clusters (
ewith its acute accent would be one grapheme cluster):
$ perl -CLAS -le 'for (@ARGV) {print for /X/g}' $'Steu301phane'
S
t
é
p
h
a
n
e
(or
grep -Po 'X'with GNU grep built with PCRE support)
With characters (here with GNU
grep):
$ printf '%sn' $'Steu301phane' | grep -o .
S
t
e
p
h
a
n
e
foldis meant to break on characters, but GNUfolddoesn't support multi-byte characters, so it breaks on bytes instead:
$ printf '%sn' $'Steu301phane' | fold -w 1
S
t
e
�
�
p
h
a
n
e
On StackOver which only consists of ASCII characters (so one byte per character, one character per grapheme cluster), all three would give the same result.
edited Aug 31 '18 at 6:34
answered Jan 5 '16 at 0:07
Stéphane ChazelasStéphane Chazelas
305k57574929
305k57574929
I'm surprisedgrep -Podoesn't do what one would expect (likegrep -Pdoes).
– jimmij
Jan 5 '16 at 0:19
@jimmij, what do you mean?grep -Po .finds characters (and a combining acute accent following a newline character is invalid), andgrep -Po 'X'finds graphem clusters for me. You may need a recent version of grep and/or PCRE for it to work properly (or trygrep -Po '(*UTF8)X')
– Stéphane Chazelas
Jan 5 '16 at 0:23
2
@SijaanHallak These might be helpful: joelonsoftware.com/articles/Unicode.html, eev.ee/blog/2015/09/12/dark-corners-of-unicode
– jpmc26
Jan 5 '16 at 21:55
add a comment |
I'm surprisedgrep -Podoesn't do what one would expect (likegrep -Pdoes).
– jimmij
Jan 5 '16 at 0:19
@jimmij, what do you mean?grep -Po .finds characters (and a combining acute accent following a newline character is invalid), andgrep -Po 'X'finds graphem clusters for me. You may need a recent version of grep and/or PCRE for it to work properly (or trygrep -Po '(*UTF8)X')
– Stéphane Chazelas
Jan 5 '16 at 0:23
2
@SijaanHallak These might be helpful: joelonsoftware.com/articles/Unicode.html, eev.ee/blog/2015/09/12/dark-corners-of-unicode
– jpmc26
Jan 5 '16 at 21:55
I'm surprised
grep -Po doesn't do what one would expect (like grep -P does).– jimmij
Jan 5 '16 at 0:19
I'm surprised
grep -Po doesn't do what one would expect (like grep -P does).– jimmij
Jan 5 '16 at 0:19
@jimmij, what do you mean?
grep -Po . finds characters (and a combining acute accent following a newline character is invalid), and grep -Po 'X' finds graphem clusters for me. You may need a recent version of grep and/or PCRE for it to work properly (or try grep -Po '(*UTF8)X')– Stéphane Chazelas
Jan 5 '16 at 0:23
@jimmij, what do you mean?
grep -Po . finds characters (and a combining acute accent following a newline character is invalid), and grep -Po 'X' finds graphem clusters for me. You may need a recent version of grep and/or PCRE for it to work properly (or try grep -Po '(*UTF8)X')– Stéphane Chazelas
Jan 5 '16 at 0:23
2
2
@SijaanHallak These might be helpful: joelonsoftware.com/articles/Unicode.html, eev.ee/blog/2015/09/12/dark-corners-of-unicode
– jpmc26
Jan 5 '16 at 21:55
@SijaanHallak These might be helpful: joelonsoftware.com/articles/Unicode.html, eev.ee/blog/2015/09/12/dark-corners-of-unicode
– jpmc26
Jan 5 '16 at 21:55
add a comment |
If you have perl6 in your box:
$ perl6 -e 'for @*ARGS -> $w { .say for $w.comb }' 'cường'
c
ư
ờ
n
g
work regardless of your locale.
add a comment |
If you have perl6 in your box:
$ perl6 -e 'for @*ARGS -> $w { .say for $w.comb }' 'cường'
c
ư
ờ
n
g
work regardless of your locale.
add a comment |
If you have perl6 in your box:
$ perl6 -e 'for @*ARGS -> $w { .say for $w.comb }' 'cường'
c
ư
ờ
n
g
work regardless of your locale.
If you have perl6 in your box:
$ perl6 -e 'for @*ARGS -> $w { .say for $w.comb }' 'cường'
c
ư
ờ
n
g
work regardless of your locale.
answered Jan 5 '16 at 1:42
cuonglmcuonglm
104k24203302
104k24203302
add a comment |
add a comment |
With many awk versions
awk -F '' -v OFS='n' '{$1=$1};1' <<<'StackOver'
Great! But on my version of nAWK ("One True AWK") that doesn't work. However this does the trick:awk -v FS='' -v OFS='n' '{$1=$1};1'(wondering if that's more portable since-F ''might yield the ERE://)
– eruve
Feb 4 at 6:48
add a comment |
With many awk versions
awk -F '' -v OFS='n' '{$1=$1};1' <<<'StackOver'
Great! But on my version of nAWK ("One True AWK") that doesn't work. However this does the trick:awk -v FS='' -v OFS='n' '{$1=$1};1'(wondering if that's more portable since-F ''might yield the ERE://)
– eruve
Feb 4 at 6:48
add a comment |
With many awk versions
awk -F '' -v OFS='n' '{$1=$1};1' <<<'StackOver'
With many awk versions
awk -F '' -v OFS='n' '{$1=$1};1' <<<'StackOver'
edited Jan 5 '16 at 22:11
Stéphane Chazelas
305k57574929
305k57574929
answered Jan 5 '16 at 4:16
iruvariruvar
11.9k62960
11.9k62960
Great! But on my version of nAWK ("One True AWK") that doesn't work. However this does the trick:awk -v FS='' -v OFS='n' '{$1=$1};1'(wondering if that's more portable since-F ''might yield the ERE://)
– eruve
Feb 4 at 6:48
add a comment |
Great! But on my version of nAWK ("One True AWK") that doesn't work. However this does the trick:awk -v FS='' -v OFS='n' '{$1=$1};1'(wondering if that's more portable since-F ''might yield the ERE://)
– eruve
Feb 4 at 6:48
Great! But on my version of nAWK ("One True AWK") that doesn't work. However this does the trick:
awk -v FS='' -v OFS='n' '{$1=$1};1' (wondering if that's more portable since -F '' might yield the ERE: //)– eruve
Feb 4 at 6:48
Great! But on my version of nAWK ("One True AWK") that doesn't work. However this does the trick:
awk -v FS='' -v OFS='n' '{$1=$1};1' (wondering if that's more portable since -F '' might yield the ERE: //)– eruve
Feb 4 at 6:48
add a comment |
The below will be generic:
$ awk -F ''
'BEGIN { RS = ""; OFS = "n"} {for (i=1;i<=NF;i++) $i = $i; print }' <file_name>
add a comment |
The below will be generic:
$ awk -F ''
'BEGIN { RS = ""; OFS = "n"} {for (i=1;i<=NF;i++) $i = $i; print }' <file_name>
add a comment |
The below will be generic:
$ awk -F ''
'BEGIN { RS = ""; OFS = "n"} {for (i=1;i<=NF;i++) $i = $i; print }' <file_name>
The below will be generic:
$ awk -F ''
'BEGIN { RS = ""; OFS = "n"} {for (i=1;i<=NF;i++) $i = $i; print }' <file_name>
edited Jan 5 '16 at 7:24
slm♦
251k66528685
251k66528685
answered Jan 5 '16 at 6:56
user150073user150073
411
411
add a comment |
add a comment |
echo StackOver | sed -e 's/./&n/g'
S
t
a
c
k
O
v
e
r
This won't help as it prints a new line at the end
– Sijaan Hallak
Jan 5 '16 at 10:56
add a comment |
echo StackOver | sed -e 's/./&n/g'
S
t
a
c
k
O
v
e
r
This won't help as it prints a new line at the end
– Sijaan Hallak
Jan 5 '16 at 10:56
add a comment |
echo StackOver | sed -e 's/./&n/g'
S
t
a
c
k
O
v
e
r
echo StackOver | sed -e 's/./&n/g'
S
t
a
c
k
O
v
e
r
edited Jan 5 '16 at 14:37
mikeserv
45.6k668157
45.6k668157
answered Jan 5 '16 at 4:11
hendersonhenderson
391
391
This won't help as it prints a new line at the end
– Sijaan Hallak
Jan 5 '16 at 10:56
add a comment |
This won't help as it prints a new line at the end
– Sijaan Hallak
Jan 5 '16 at 10:56
This won't help as it prints a new line at the end
– Sijaan Hallak
Jan 5 '16 at 10:56
This won't help as it prints a new line at the end
– Sijaan Hallak
Jan 5 '16 at 10:56
add a comment |
Since you specifically asked for an answer in bash, here's a way to do it in pure bash:
while read -rn1; do echo "$REPLY" ; done <<< "StackOver"
Note that this will catch the newline at the end of the "here document". If you want to avoid that, but still iterate over the characters with a bash loop, use printf to avoid the newline.
printf StackOver | while read -rn1; do echo "$REPLY" ; done
add a comment |
Since you specifically asked for an answer in bash, here's a way to do it in pure bash:
while read -rn1; do echo "$REPLY" ; done <<< "StackOver"
Note that this will catch the newline at the end of the "here document". If you want to avoid that, but still iterate over the characters with a bash loop, use printf to avoid the newline.
printf StackOver | while read -rn1; do echo "$REPLY" ; done
add a comment |
Since you specifically asked for an answer in bash, here's a way to do it in pure bash:
while read -rn1; do echo "$REPLY" ; done <<< "StackOver"
Note that this will catch the newline at the end of the "here document". If you want to avoid that, but still iterate over the characters with a bash loop, use printf to avoid the newline.
printf StackOver | while read -rn1; do echo "$REPLY" ; done
Since you specifically asked for an answer in bash, here's a way to do it in pure bash:
while read -rn1; do echo "$REPLY" ; done <<< "StackOver"
Note that this will catch the newline at the end of the "here document". If you want to avoid that, but still iterate over the characters with a bash loop, use printf to avoid the newline.
printf StackOver | while read -rn1; do echo "$REPLY" ; done
edited Jan 5 '16 at 22:34
Stéphane Chazelas
305k57574929
305k57574929
answered Jan 5 '16 at 22:16
wyrmwyrm
32015
32015
add a comment |
add a comment |
Also Python 2 can be used from the command line:
python <<< "for x in 'StackOver':
print x"
or:
echo "for x in 'StackOver':
print x" | python
or (as commented by 1_CR) with Python 3:
python3 -c "print(*'StackOver',sep='n')"
add a comment |
Also Python 2 can be used from the command line:
python <<< "for x in 'StackOver':
print x"
or:
echo "for x in 'StackOver':
print x" | python
or (as commented by 1_CR) with Python 3:
python3 -c "print(*'StackOver',sep='n')"
add a comment |
Also Python 2 can be used from the command line:
python <<< "for x in 'StackOver':
print x"
or:
echo "for x in 'StackOver':
print x" | python
or (as commented by 1_CR) with Python 3:
python3 -c "print(*'StackOver',sep='n')"
Also Python 2 can be used from the command line:
python <<< "for x in 'StackOver':
print x"
or:
echo "for x in 'StackOver':
print x" | python
or (as commented by 1_CR) with Python 3:
python3 -c "print(*'StackOver',sep='n')"
edited Jan 6 '16 at 10:12
terdon♦
130k32255433
130k32255433
answered Jan 5 '16 at 11:57
agoldagold
363311
363311
add a comment |
add a comment |
You can use the fold (1) command. It is more efficient than grep and sed.
$ time grep -o . <bigfile >/dev/null
real 0m3.868s
user 0m3.784s
sys 0m0.056s
$ time fold -b1 <bigfile >/dev/null
real 0m0.555s
user 0m0.528s
sys 0m0.016s
$
One significant difference is that fold will reproduce empty lines in the output:
$ grep -o . <(printf "AnBnnCnnnDn")
A
B
C
D
$ fold -b1 <(printf "AnBnnCnnnDn")
A
B
C
D
$
add a comment |
You can use the fold (1) command. It is more efficient than grep and sed.
$ time grep -o . <bigfile >/dev/null
real 0m3.868s
user 0m3.784s
sys 0m0.056s
$ time fold -b1 <bigfile >/dev/null
real 0m0.555s
user 0m0.528s
sys 0m0.016s
$
One significant difference is that fold will reproduce empty lines in the output:
$ grep -o . <(printf "AnBnnCnnnDn")
A
B
C
D
$ fold -b1 <(printf "AnBnnCnnnDn")
A
B
C
D
$
add a comment |
You can use the fold (1) command. It is more efficient than grep and sed.
$ time grep -o . <bigfile >/dev/null
real 0m3.868s
user 0m3.784s
sys 0m0.056s
$ time fold -b1 <bigfile >/dev/null
real 0m0.555s
user 0m0.528s
sys 0m0.016s
$
One significant difference is that fold will reproduce empty lines in the output:
$ grep -o . <(printf "AnBnnCnnnDn")
A
B
C
D
$ fold -b1 <(printf "AnBnnCnnnDn")
A
B
C
D
$
You can use the fold (1) command. It is more efficient than grep and sed.
$ time grep -o . <bigfile >/dev/null
real 0m3.868s
user 0m3.784s
sys 0m0.056s
$ time fold -b1 <bigfile >/dev/null
real 0m0.555s
user 0m0.528s
sys 0m0.016s
$
One significant difference is that fold will reproduce empty lines in the output:
$ grep -o . <(printf "AnBnnCnnnDn")
A
B
C
D
$ fold -b1 <(printf "AnBnnCnnnDn")
A
B
C
D
$
edited Jan 6 '16 at 10:19
answered Jan 6 '16 at 5:45
joeytwiddlejoeytwiddle
55939
55939
add a comment |
add a comment |
You can handle multibyte characters like:
<input
dd cbs=1 obs=2 conv=unblock |
sed -e:c -e '/^.*$/!N;s/n//;tc'
Which can be pretty handy when you're working with live input because there's no buffering there and a character is printed as soon it is whole.
NP, should we add a note about the locale?
– cuonglm
Jan 5 '16 at 9:35
Does not work for combining characters like Stéphane Chazelas answer, but with proper normalization this should not matter.
– kay
Jan 5 '16 at 13:06
@Kay - it's works for combining characters if you want it to - that's whatsedscripts are for. i'm not likely to write one right about now - im pretty sleepy. it's really useful, though, when reading a terminal.
– mikeserv
Jan 5 '16 at 14:30
@cuonglm - if you like. it should just work for the locale, given a sane libc, though.
– mikeserv
Jan 5 '16 at 14:33
Note thatddwill break multibyte characters, so the output will not be text anymore so the behaviour of sed will be unspecified as per POSIX.
– Stéphane Chazelas
Jan 5 '16 at 22:09
|
show 2 more comments
You can handle multibyte characters like:
<input
dd cbs=1 obs=2 conv=unblock |
sed -e:c -e '/^.*$/!N;s/n//;tc'
Which can be pretty handy when you're working with live input because there's no buffering there and a character is printed as soon it is whole.
NP, should we add a note about the locale?
– cuonglm
Jan 5 '16 at 9:35
Does not work for combining characters like Stéphane Chazelas answer, but with proper normalization this should not matter.
– kay
Jan 5 '16 at 13:06
@Kay - it's works for combining characters if you want it to - that's whatsedscripts are for. i'm not likely to write one right about now - im pretty sleepy. it's really useful, though, when reading a terminal.
– mikeserv
Jan 5 '16 at 14:30
@cuonglm - if you like. it should just work for the locale, given a sane libc, though.
– mikeserv
Jan 5 '16 at 14:33
Note thatddwill break multibyte characters, so the output will not be text anymore so the behaviour of sed will be unspecified as per POSIX.
– Stéphane Chazelas
Jan 5 '16 at 22:09
|
show 2 more comments
You can handle multibyte characters like:
<input
dd cbs=1 obs=2 conv=unblock |
sed -e:c -e '/^.*$/!N;s/n//;tc'
Which can be pretty handy when you're working with live input because there's no buffering there and a character is printed as soon it is whole.
You can handle multibyte characters like:
<input
dd cbs=1 obs=2 conv=unblock |
sed -e:c -e '/^.*$/!N;s/n//;tc'
Which can be pretty handy when you're working with live input because there's no buffering there and a character is printed as soon it is whole.
edited Jan 5 '16 at 7:27
cuonglm
104k24203302
104k24203302
answered Jan 5 '16 at 1:12
mikeservmikeserv
45.6k668157
45.6k668157
NP, should we add a note about the locale?
– cuonglm
Jan 5 '16 at 9:35
Does not work for combining characters like Stéphane Chazelas answer, but with proper normalization this should not matter.
– kay
Jan 5 '16 at 13:06
@Kay - it's works for combining characters if you want it to - that's whatsedscripts are for. i'm not likely to write one right about now - im pretty sleepy. it's really useful, though, when reading a terminal.
– mikeserv
Jan 5 '16 at 14:30
@cuonglm - if you like. it should just work for the locale, given a sane libc, though.
– mikeserv
Jan 5 '16 at 14:33
Note thatddwill break multibyte characters, so the output will not be text anymore so the behaviour of sed will be unspecified as per POSIX.
– Stéphane Chazelas
Jan 5 '16 at 22:09
|
show 2 more comments
NP, should we add a note about the locale?
– cuonglm
Jan 5 '16 at 9:35
Does not work for combining characters like Stéphane Chazelas answer, but with proper normalization this should not matter.
– kay
Jan 5 '16 at 13:06
@Kay - it's works for combining characters if you want it to - that's whatsedscripts are for. i'm not likely to write one right about now - im pretty sleepy. it's really useful, though, when reading a terminal.
– mikeserv
Jan 5 '16 at 14:30
@cuonglm - if you like. it should just work for the locale, given a sane libc, though.
– mikeserv
Jan 5 '16 at 14:33
Note thatddwill break multibyte characters, so the output will not be text anymore so the behaviour of sed will be unspecified as per POSIX.
– Stéphane Chazelas
Jan 5 '16 at 22:09
NP, should we add a note about the locale?
– cuonglm
Jan 5 '16 at 9:35
NP, should we add a note about the locale?
– cuonglm
Jan 5 '16 at 9:35
Does not work for combining characters like Stéphane Chazelas answer, but with proper normalization this should not matter.
– kay
Jan 5 '16 at 13:06
Does not work for combining characters like Stéphane Chazelas answer, but with proper normalization this should not matter.
– kay
Jan 5 '16 at 13:06
@Kay - it's works for combining characters if you want it to - that's what
sed scripts are for. i'm not likely to write one right about now - im pretty sleepy. it's really useful, though, when reading a terminal.– mikeserv
Jan 5 '16 at 14:30
@Kay - it's works for combining characters if you want it to - that's what
sed scripts are for. i'm not likely to write one right about now - im pretty sleepy. it's really useful, though, when reading a terminal.– mikeserv
Jan 5 '16 at 14:30
@cuonglm - if you like. it should just work for the locale, given a sane libc, though.
– mikeserv
Jan 5 '16 at 14:33
@cuonglm - if you like. it should just work for the locale, given a sane libc, though.
– mikeserv
Jan 5 '16 at 14:33
Note that
dd will break multibyte characters, so the output will not be text anymore so the behaviour of sed will be unspecified as per POSIX.– Stéphane Chazelas
Jan 5 '16 at 22:09
Note that
dd will break multibyte characters, so the output will not be text anymore so the behaviour of sed will be unspecified as per POSIX.– Stéphane Chazelas
Jan 5 '16 at 22:09
|
show 2 more comments
You may use word boundaries also..
$ perl -pe 's/(?<=.)(B|b)(?=.)/n/g' <<< "StackOver"
S
t
a
c
k
O
v
e
r
add a comment |
You may use word boundaries also..
$ perl -pe 's/(?<=.)(B|b)(?=.)/n/g' <<< "StackOver"
S
t
a
c
k
O
v
e
r
add a comment |
You may use word boundaries also..
$ perl -pe 's/(?<=.)(B|b)(?=.)/n/g' <<< "StackOver"
S
t
a
c
k
O
v
e
r
You may use word boundaries also..
$ perl -pe 's/(?<=.)(B|b)(?=.)/n/g' <<< "StackOver"
S
t
a
c
k
O
v
e
r
answered Jan 5 '16 at 9:31
Avinash RajAvinash Raj
2,60731227
2,60731227
add a comment |
add a comment |
In bash:
This works with any text and with only bash internals (no external utility called), so, should be fast on very short strings.
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
(set -- "${BASH_REMATCH[@]:1}"; IFS=$'n'; echo "$*")
Output:
S
t
é
p
h
a
n
e
á
à
é
è
ë
ê
ế
e
If it is ok to change IFS and to change the positional parameters, you can also avoid the sub-shell call:
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
set -- "${BASH_REMATCH[@]:1}"
IFS=$'n'
echo "$*"
add a comment |
In bash:
This works with any text and with only bash internals (no external utility called), so, should be fast on very short strings.
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
(set -- "${BASH_REMATCH[@]:1}"; IFS=$'n'; echo "$*")
Output:
S
t
é
p
h
a
n
e
á
à
é
è
ë
ê
ế
e
If it is ok to change IFS and to change the positional parameters, you can also avoid the sub-shell call:
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
set -- "${BASH_REMATCH[@]:1}"
IFS=$'n'
echo "$*"
add a comment |
In bash:
This works with any text and with only bash internals (no external utility called), so, should be fast on very short strings.
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
(set -- "${BASH_REMATCH[@]:1}"; IFS=$'n'; echo "$*")
Output:
S
t
é
p
h
a
n
e
á
à
é
è
ë
ê
ế
e
If it is ok to change IFS and to change the positional parameters, you can also avoid the sub-shell call:
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
set -- "${BASH_REMATCH[@]:1}"
IFS=$'n'
echo "$*"
In bash:
This works with any text and with only bash internals (no external utility called), so, should be fast on very short strings.
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
(set -- "${BASH_REMATCH[@]:1}"; IFS=$'n'; echo "$*")
Output:
S
t
é
p
h
a
n
e
á
à
é
è
ë
ê
ế
e
If it is ok to change IFS and to change the positional parameters, you can also avoid the sub-shell call:
str="Stéphane áàéèëêếe"
[[ $str =~ ${str//?/(.)} ]]
set -- "${BASH_REMATCH[@]:1}"
IFS=$'n'
echo "$*"
answered Nov 23 '16 at 21:37
sorontarsorontar
4,448928
4,448928
add a comment |
add a comment |
s=stackoverflow;
$ time echo $s | fold -w1
s
t
a
c
k
o
v
e
r
real 0m0.014s
user 0m0.000s
sys 0m0.004s
updates
here is the hacky|fastest|pureBashBased way !
$ time eval eval printf '%s\\n' \${s:{0..$((${#s}-1))}:1}
s
t
a
c
k
o
v
e
r
real 0m0.001s
user 0m0.000s
sys 0m0.000s
for more awesomeness
function foldh ()
{
if (($#)); then
local s="$@";
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
function foldv ()
{
if (($#)); then
local s="$@";
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
Will this ever give different results tofold -b1?
– JigglyNaga
Jul 25 '16 at 12:10
since each byte have a width=1 the result will be the same !
– Jonas
Jul 25 '16 at 12:30
1
So how is this not a duplicate of the earlier answer?
– JigglyNaga
Jul 25 '16 at 13:17
because it shows tha same cmd with different argyment , and that is nice to know .
– Jonas
Jul 25 '16 at 13:45
add a comment |
s=stackoverflow;
$ time echo $s | fold -w1
s
t
a
c
k
o
v
e
r
real 0m0.014s
user 0m0.000s
sys 0m0.004s
updates
here is the hacky|fastest|pureBashBased way !
$ time eval eval printf '%s\\n' \${s:{0..$((${#s}-1))}:1}
s
t
a
c
k
o
v
e
r
real 0m0.001s
user 0m0.000s
sys 0m0.000s
for more awesomeness
function foldh ()
{
if (($#)); then
local s="$@";
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
function foldv ()
{
if (($#)); then
local s="$@";
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
Will this ever give different results tofold -b1?
– JigglyNaga
Jul 25 '16 at 12:10
since each byte have a width=1 the result will be the same !
– Jonas
Jul 25 '16 at 12:30
1
So how is this not a duplicate of the earlier answer?
– JigglyNaga
Jul 25 '16 at 13:17
because it shows tha same cmd with different argyment , and that is nice to know .
– Jonas
Jul 25 '16 at 13:45
add a comment |
s=stackoverflow;
$ time echo $s | fold -w1
s
t
a
c
k
o
v
e
r
real 0m0.014s
user 0m0.000s
sys 0m0.004s
updates
here is the hacky|fastest|pureBashBased way !
$ time eval eval printf '%s\\n' \${s:{0..$((${#s}-1))}:1}
s
t
a
c
k
o
v
e
r
real 0m0.001s
user 0m0.000s
sys 0m0.000s
for more awesomeness
function foldh ()
{
if (($#)); then
local s="$@";
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
function foldv ()
{
if (($#)); then
local s="$@";
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
s=stackoverflow;
$ time echo $s | fold -w1
s
t
a
c
k
o
v
e
r
real 0m0.014s
user 0m0.000s
sys 0m0.004s
updates
here is the hacky|fastest|pureBashBased way !
$ time eval eval printf '%s\\n' \${s:{0..$((${#s}-1))}:1}
s
t
a
c
k
o
v
e
r
real 0m0.001s
user 0m0.000s
sys 0m0.000s
for more awesomeness
function foldh ()
{
if (($#)); then
local s="$@";
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval printf '%s\\n' \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
function foldv ()
{
if (($#)); then
local s="$@";
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
else
while read s; do
eval eval echo \"\${s:{0..$((${#s}-1))}:1}\";
done;
fi
}
edited May 20 '17 at 21:49
answered Jul 25 '16 at 12:01
JonasJonas
883515
883515
Will this ever give different results tofold -b1?
– JigglyNaga
Jul 25 '16 at 12:10
since each byte have a width=1 the result will be the same !
– Jonas
Jul 25 '16 at 12:30
1
So how is this not a duplicate of the earlier answer?
– JigglyNaga
Jul 25 '16 at 13:17
because it shows tha same cmd with different argyment , and that is nice to know .
– Jonas
Jul 25 '16 at 13:45
add a comment |
Will this ever give different results tofold -b1?
– JigglyNaga
Jul 25 '16 at 12:10
since each byte have a width=1 the result will be the same !
– Jonas
Jul 25 '16 at 12:30
1
So how is this not a duplicate of the earlier answer?
– JigglyNaga
Jul 25 '16 at 13:17
because it shows tha same cmd with different argyment , and that is nice to know .
– Jonas
Jul 25 '16 at 13:45
Will this ever give different results to
fold -b1 ?– JigglyNaga
Jul 25 '16 at 12:10
Will this ever give different results to
fold -b1 ?– JigglyNaga
Jul 25 '16 at 12:10
since each byte have a width=1 the result will be the same !
– Jonas
Jul 25 '16 at 12:30
since each byte have a width=1 the result will be the same !
– Jonas
Jul 25 '16 at 12:30
1
1
So how is this not a duplicate of the earlier answer?
– JigglyNaga
Jul 25 '16 at 13:17
So how is this not a duplicate of the earlier answer?
– JigglyNaga
Jul 25 '16 at 13:17
because it shows tha same cmd with different argyment , and that is nice to know .
– Jonas
Jul 25 '16 at 13:45
because it shows tha same cmd with different argyment , and that is nice to know .
– Jonas
Jul 25 '16 at 13:45
add a comment |
read -a var <<< $(echo "$yourWordhere" | grep -o "." | tr 'n' ' ')
this will split your word and store it in array var.
add a comment |
read -a var <<< $(echo "$yourWordhere" | grep -o "." | tr 'n' ' ')
this will split your word and store it in array var.
add a comment |
read -a var <<< $(echo "$yourWordhere" | grep -o "." | tr 'n' ' ')
this will split your word and store it in array var.
read -a var <<< $(echo "$yourWordhere" | grep -o "." | tr 'n' ' ')
this will split your word and store it in array var.
edited Aug 31 '18 at 11:30
αғsнιη
16.8k102865
16.8k102865
answered Aug 31 '18 at 3:43
Chinmay KatilChinmay Katil
111
111
add a comment |
add a comment |
for x in $(echo "$yourWordhere" | grep -o '.')
do
code to perform operation on individual character $x of your word
done
add a comment |
for x in $(echo "$yourWordhere" | grep -o '.')
do
code to perform operation on individual character $x of your word
done
add a comment |
for x in $(echo "$yourWordhere" | grep -o '.')
do
code to perform operation on individual character $x of your word
done
for x in $(echo "$yourWordhere" | grep -o '.')
do
code to perform operation on individual character $x of your word
done
edited 8 mins ago
phuclv
390121
390121
answered Sep 12 '18 at 7:28
Chinmay KatilChinmay Katil
111
111
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f253279%2fbash-script-split-word-on-each-letter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown