Replace comma with new line in MacOS terminal bash shell script [duplicate] - bash

This question already has answers here:
How to add new line using sed on MacOS?
(3 answers)
Closed 2 years ago.
I'm trying to replace each comma with a new line.
e.g. when I do the following
echo abc,wer | sed 's/\,/\n/g'
I hope to get
abc
wer
However, I got
abcnwer
What did I do wrong?

Based on #MarkSetchell answer above, the below works.
echo abc,wer | tr , '\n'

Related

How to extract string between IDs in shell [duplicate]

This question already has answers here:
How to use sed/grep to extract text between two words?
(14 answers)
Closed 2 years ago.
I have a string that looks like this:
RG="#RG\tID:HS2000-1015_160.7\tDS:ADNI_1380^LP6005117-DNA_G04^ADNI_WGS\tLB:LP6005117-DNA_G04\tPL:illumina\tPU:HS2000-1015_160.7\tSM:ADNI_1380"
I want to extract everything after ID: and before first the \t
and get HS2000-1015_160.7 as a result. I would like a one-liner if possible.
code I tried:
echo ${RG} | grep -oP "(?<=ID:)[^"\t"]*"
which gives me HS2000-1015_160.7\
Try:
sed 's/.*ID://;s/\\t.*//'
s/.*ID:// remove everything in front and including ID:
s/\\t.*//' remove everything after and including \t characters.

storing result of awk in shell script [duplicate]

This question already has answers here:
How to split a string into an array in Bash?
(24 answers)
How do I split a string on a delimiter in Bash?
(37 answers)
Closed 3 years ago.
I am new to shell script and I have started it today itself. Can anyone tell me how to store and retrieve the output of this command:
cat /proc/cpuinfo | grep "MHz" | awk '/cpu MHz/ {print $4}'
This command returns just four decimal numbers but I am struggling to store these four numbers.
I have tried to store them in array but it has not been fruitful for me. Please help!!

Using grep to filter real time output of a process? If so, how to get the line after a match? [duplicate]

This question already has answers here:
How to show only next line after the matched one?
(14 answers)
grep: show lines surrounding each match
(14 answers)
Read from a endless pipe bash [duplicate]
(1 answer)
Closed 4 years ago.
Should I use grep to filter a real time output? I'm not sure if this is what I should use for a real time output.
Example: command -option | grep --color 'string1\|string2'
If so, how to get also the lines after string1 and string2?
As #shellter mentioned, from man grep:
-A num, --after-context=num
Print num lines of trailing context after each match. See also the -B and -C options.
so you would use command -option | grep -A 1 --color 'string1\|string2' to print matched lines and the line right after them.
There are plenty of other options in the manual for grep, and most other command-line programs, so I suggest getting used to running man cmd as a quick first check.

Linux- Removing from specific line number to specific line number [duplicate]

This question already has answers here:
Delete lines from file with SED or AWK
(3 answers)
Closed 8 years ago.
I want to remove contents from line number 23 to line number 69 in file file.txt. Is there any command I can use to do that?
Thanks in advance
You can use sed with d command and inline editing option:
sed -i.bak '23,69d' file

Using sed Command [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Join lines based on pattern
I have the following file:
test
one
My
two
Hi
three
i need a way to use cat and sed to give the following output:
testone
Mytwo
Hithree
How can i achieve this in a single command?
Where the file "foo.txt" contains your text:
cat foo.txt | sed -e 'N;s/\n//'

Resources