Is it possible to cut
a string without a line break?
printf 'test.test'
prints the test.test
without a newline.
But if I cut the output with printf 'test.test' | cut -d. -f1
there's a newline behind test
.
Is it possible to cut
a string without a line break?
printf 'test.test'
prints the test.test
without a newline.
But if I cut the output with printf 'test.test' | cut -d. -f1
there's a newline behind test
.
There are many ways. In addition to isedev and fedorqui's answers, you could also do:
perl -ne '/^([^.]+)/ && print $1' <<< "test.test"
cut -d. -f1 <<< "test.test" | tr -d $'\n'
cut -d. -f1 <<< "test.test" | perl -pe 's/\n//'
while read -d. i; do printf "%s" "$i"; done <<< "test.test
If you don't have to use cut
, you can achieve the same result with awk
:
printf 'test.test' | awk -F. '{printf($1)}'
No that I know. man cut
is quite short and doesn't reflect anything similar.
Instead, you can provide the cut
output to printf
with a here-string, so that the new line issue depends again on printf
:
printf '%s' $(cut -d. -f1 <<< "test.test")