i am trying to make this script that filters a line coming from ps..
the script it almost done, only this line missing.
for example,here’s a line i need to filter :
803 ? (many spaces here) 00:00:00 atd
i need this like to look like this :
803 atd
i’ve tried everything but it seems that a simple sed argument can’t do this.. if sed detects something that has to be erased, it deletes the whole line after it..
please correct me if i am wrong and thanks for your time..
Try this command for sed:
It takes the first space, as much as possible, then the last space, and replaces them with a single space.
If you can have spaces at the beginning or the end of the string, then you need to be a little more careful with your sed command. It’s not nearly as elegant here:
This captures non-space characters and puts them in the output stream. Without an extended sed like GNU sed, you need to replace the occurrences of
[^ ]\+with[^ ][^ ]*.That being said,
awkis clearly the most graceful tool for this job.