D
D
deptk2019-10-29 12:26:40
linux
deptk, 2019-10-29 12:26:40

How to remove a character in command output in Linux?

There is an output of a certain command in Linux (the whole output is one line):

[ { " *тут кучка данных*", "Last Share Time": "0:01:05", "*и тут еще кучка* } ]

At what "Last Share Time": "0:01:05", is repeated several times in the output.
I need to make "00105" from "0:01:05".
I tried to do it through the sed command, I could only do this: I.e. replaced "0:01:05" entirely with "BLABLABLA" How can I remove only the colon in this particular sequence of "0:01:05" ? The colon occurs multiple times in the output. "0:01:05" is the time output as a string sed "s/[0-9]\{1\}:[0-9]\{2\}/BLABLABLA/g"

Answer the question

In order to leave comments, you need to log in

6 answer(s)
X
xibir, 2019-10-29
@deptk

sed -r 's/([0-9]):([0-9][0-9]):([0-9][0-9])/\1\2\3/'

V
vreitech, 2019-10-29
@fzfx

perl -pe 's/(\d{1,2}):(\d{1,2}):(\d{1,2})/\1\2\3/g'

S
Saboteur, 2019-10-29
@saboteur_kiev

It is possible in awk on your example. I use quotation marks as a delimiter.

VAR='[ { " *тут кучка данных*", "Last Share Time": "0:01:05", "*и тут еще кучка*" } ]'

echo "$VAR"
echo "$VAR" | awk 'BEGIN{FS="\"";OFS="\""} {gsub(/:|\;/,"",$6)}1'

R
Radjah, 2019-10-29
@Radjah

I would jq -rselect the required fields with sed, then remove the ":" with sed.

S
sergey, 2019-10-29
kuzmin @sergueik

Radjah for sure, and jq also has a developed data filter syntax (you need to look at the data exactly what to choose)

A
Alexey Leontiev, 2019-10-30
@BEERsk

tr -d ":"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question