Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Replacing all lines of a command output
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Marcus613
n00b
n00b


Joined: 28 Feb 2024
Posts: 19

PostPosted: Sat Mar 02, 2024 4:46 am    Post subject: Replacing all lines of a command output Reply with quote

Hi

I'm using genlop to display a message when emerging a package. The command I use is "genlop -ci".
When no package is being emerged, the following two lines are returnes:

Code:
!!! Error: no working merge found.
(the -c option only works if there is an ongoing compilation, see manpage)


But in that case I want ton display nothing, an empty string: ""

I did this with the following command (witch display two empty lines in that case):

Code:
genlop -ci | awk 'NR==1 && /^!!! Error/ {print ""} NR!=1' | awk 'NR==1 && /^\(the -c option/ {print ""} NR!=1'


Is there a better way to do this and tell awk (or something else) "if first line starts with this patern then replaces every lines with this patern" ?
Back to top
View user's profile Send private message
freke
l33t
l33t


Joined: 23 Jan 2003
Posts: 977
Location: Somewhere in Denmark

PostPosted: Sat Mar 02, 2024 8:16 am    Post subject: Reply with quote

Alternatively you could try
Code:
qlop -rtH
from app-portage/portage-utils, it defaults to no output if no running emerge.

Output when emerging is a little different though
Code:
2024-03-02T09:14:39 >>> app-portage/eix: 7 seconds... (1 of 1) ETA: 55 seconds
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3627

PostPosted: Sat Mar 02, 2024 9:38 am    Post subject: Reply with quote

I've just tested genlop -ci which returned $?=0 when no current emerge build process.
Maybe upstream could improve that...

I've removed app-portage/genlop package in favor of qlop from app-portage/portage-utils as it may additionally remove dev-perl/Date-Manip depending on remaining package dependency tree.

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here.
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
Leonardo.b
Apprentice
Apprentice


Joined: 10 Oct 2020
Posts: 297

PostPosted: Sat Mar 02, 2024 9:38 am    Post subject: Reply with quote

In awk, you can call exit to terminate early without printing anything.
Otherwise, to work with multiple lines, you may look into getline builtin function.
Back to top
View user's profile Send private message
Marcus613
n00b
n00b


Joined: 28 Feb 2024
Posts: 19

PostPosted: Sat Mar 02, 2024 9:45 am    Post subject: Reply with quote

Leonardo.b wrote:
In awk, you can call exit to terminate early without printing anything.
Otherwise, to work with multiple lines, you may look into getline builtin function.



Could you show how to do that please ?

qlop seems interesting but it looks like you need privileges to run it.
But I'll definitely check this one
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum