Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using uptime and a few random unxutils tools to get uptime - the idea being that if it works here, I can use the same basic design for arbitrary information tools without needing to learn a 'grown up' scripting language. I do want it to be human readable so I want to crop out, and add in certain things.

What I need to do is, for example, insert "the uptime for " in front of the output for uptime|cut -c 3- so I get "uptime for computername is 1 day<s>" as an output.

Considering I'm already using two non standard tools, ideally, I'd like it to be using stuff that's native or in unxutils, but i can adjust as needed.

EDIT: using zsh is not an option - i need the output to work on the standard cmd shell.

Edit 2: I'm using windows, as per the tags. also, added a link to ms's implimentation of uptime. also corrected an error in my 'cut' command -

share|improve this question
    
What bizarre hoops this question would have us jump through! We can use the cut command from UnxUtils in our answers but not the echo command from the very same package? That's quite arbitrary. –  JdeBP Jun 27 '11 at 9:56
    
i didn't say that ;). i said no zsh, and that it didn't work with the window's native echo. I .. kind of didn't notice unxutils had echo –  Journeyman Geek Jun 27 '11 at 9:59
    
Well now you know. (-: And there are at least two ways to invoke it even though echo is built in to CMD. Given that, and modulo the obvious changes of ; to &, barbaz's answer will work. –  JdeBP Jun 27 '11 at 10:21

3 Answers 3

up vote 2 down vote accepted

Use sed and "replace" the start of the line with your prefix:

uptime | cut -c 3- | sed "s|^|This will appear before regular output|"

share|improve this answer
    
this works, almost - i had to use double quotes for it to work –  Journeyman Geek Jun 26 '11 at 15:02
    
Untested, unfortunately, since I'm not on Windows right now. But this is how it'd work elsewhere. –  Daniel Beck Jun 26 '11 at 15:02
    
@JourneymanGeek Fixed. Thanks! –  Daniel Beck Jun 26 '11 at 15:02

I'm not familiar with Unxutils, but on unix you'd prepend your call with

echo -n "Hello World "; uptime

Since i don't use windows much and don't seem to have an uptime binary on my windows i can't really try your exact call, but in general the builtin 'echo' command coming with Unxutils zsh build seems to support the -n switch:

>UnxUtils\bin\sh
WINCOMP# echo -n "Hello "; echo World
Hello World
share|improve this answer
    
echo is the native windows echo, and just prints everything after that. the output for your command is "-n "Hello World "; uptime" –  Journeyman Geek Jun 26 '11 at 12:56
1  
@Journeyman Geek: I just tried that out using the sh binary in the UnxUtils.zip and it works fine for me –  barbaz Jun 26 '11 at 12:58
    
i can't use zsh in this case, it dosen't seem to work with /exec on the irc client i'm trying to use the script with –  Journeyman Geek Jun 26 '11 at 13:02
uptime|cut -c 2 | gawk '{printf("Uptime for computername is %d day<s>\n", $1)}'
share|improve this answer
    
i get "cut: write error : invalid arguement" - only when the gawk part of it is included. –  Journeyman Geek Jun 26 '11 at 14:44
    
It's OK i believe: gjorgjit@eeepc:~$ uptime|cut -c 2 | gawk '{printf("Uptime for computername is %d day<s>\n", $1)}' Uptime for computername is 1 day<s> gjorgjit@eeepc:~$ –  Gjorgji Taskovski Jun 26 '11 at 14:49
    
Wait, wait. I do not use as you've written in the question "uptime|cut -c =2". I'm using "uptime|cut -c 2" instead. I'm on Linux. What about you? –  Gjorgji Taskovski Jun 26 '11 at 14:52
    
windows. i'm using gawk, and cut from unxutils and the uptime tool from microsoft –  Journeyman Geek Jun 26 '11 at 14:53
    
Then, I suppose it should be: uptime|cut -c =2 | gawk '{printf("Uptime for computername is %d day<s>\n", $1)}'. Eventually uptime|cut -c =2 | gawk '{printf("Uptime for computername is %d day<s>", $1)}' if new line (\n) is causing troubles to windows. –  Gjorgji Taskovski Jun 26 '11 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.