I ran echo "\oo" | tr "\oo" " "
, and the output is:
\
\o
is not a special character, like \n
, so why is the \
not converted into a space too?
I ran echo "\oo" | tr "\oo" " "
, and the output is:
\
\o
is not a special character, like \n
, so why is the \
not converted into a space too?
I could need some help with a oneline script im building. The script should give me a list of services, which are running on the current system. I wanted to realize this with systemctl.
The current oneliner looks like this:
systemctl list-units --type service | grep -f /etc/update-motd.d/service.list
However this command always creates a blank line between the services which are listed
smbd.service loaded active running Samba SMB Daemon
uuidd.service loaded active running Daemon for generating UUIDs
virtlogd.service loaded active running Virtual machine log manager
zabbix-agent.service loaded active running Zabbix Agent
I would like to remove the empty spaces. After some google research ive found some solutions with tr (like 'tr -d ""' or 'tr -s ""'), but this doesnt seem to work. Ive even tried some solutions with grep or sed but none of them helped me wih this.
edit: following solutions I tried without success: | grep "." | sed '/^$/d | grep "\S"
Some help would be great! Thanks
I have TSV file like this:
abc_1
def_2
ghi_3
jkl_4
mno_5
I want to split that in to the:
abc
def
ghi
jkl
mno
and
1
2
3
4
5
How I can get that?
In my file mytxt
:
field1 field2
------ -------
this are numbers 12345
this letters abc def ghi
Let's say I want to store the first field in an array:
i=0
while read line; do
field_one[$i]=$(echo $line | awk '{print $1}')
echo ${field_one[i]}
((i++))
done < mytxt
That would give me the this
two times in the output.
Any ideas of how could I store them in an array and get the output:
this are numbers
this letters
I have tried changing delimiters, squeezing spaces, and using sed
, but I'm stuck. Any hint would be appreciated.
My final goal is to store both fields in an array.
I'm using Ubuntu 18.04, and recently I keep getting this error when running bash scripts: tr: command not found
. The tr
does not exists in /usr/bin
and /usr/sbin
. Also installed coreutils
but still no luck. How can I add this command to my shell?
which tr
returns nothing. This is what apt says about coreutils
:
coreutils is already the newest version (8.28-1ubuntu1).
I get Command 'tr' not found
so nothing is overriding it. /usr/bin
is in my PATH
variable.