linuxbashawksed

awk and sed not working as I expect with neofetch


I'm trying to make neofetch report that the uptime of my computer is 13.7 billion years, for an art project. I used awk to get the uptime from one invocation of the command (since uptime is constantly changing), and then tried using sed to replace the output of neofetch uptime with 13.7 billion years.

This works fine if I do it by myself in the terminal:

[nixos@nixos:~]$ neofetch uptime | sed 's/30 mins/13.7 billion years/'
uptime: 13.7 billion years

But when I try to do it with variables, it doesn't work:

neofetch uptime | sed 's/$(neofetch uptime | awk '/uptime:/ {print $2, $3, $4, $5}')/13.7 billion years/'
sed: can't read {print: No such file or directory

Edit:

neofetch uptime | sed "s/$(neofetch uptime | awk '/uptime:/ {print $2, $3, $4, $5}')/13.7 billion years/"
uptime: 14 mins

end Edit

Doing it with a script: (script.sh):

uptime_value=$(neofetch uptime | awk '/uptime:/ {print $2, $3, $4, $5}')
echo "Found uptime_value:"
echo ${uptime_value}

neofetch uptime | sed "s/${uptime_value}/13.7 billion years/"

Output:

Found uptime_value:
34 mins
uptime: 34 mins

What am I doing wrong?


Solution

  • From https://github.com/dylanaraps/neofetch/wiki/Customizing-Info and scanning the source, manipulating the output is unnecessary. You could just override the uptime function:

    echo 'get_uptime(){ uptime="13.7 billion years"; }' >> $HOME/.config/neofetch/config.conf
    

    After that, it should produce that text everywhere. For example, on my machine:

    $ neofetch distro shell uptime --uptime_shorthand tiny
    distro: Xubuntu 24.04.1 LTS x86_64 
    shell: bash 5.2.21 
    uptime: 13.7 billion years 
    $