Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've been using this perl script to get a token out of stream on command line

  1 #!/usr/bin/perl
  2 
  3 $i = $ARGV[0];
  4 
  5 while (<STDIN>) {
  6   @tokens = split /\s+/;
  7   print $tokens[$i] . "\n";
  8 }

typical usage would be something like

mjeong@login:~/bin$ qstat | grep XXX.0.par
1664011 0.00063 XXX.0.par mjeong       qw    11/05/2010 10:34:37  16        
mjeong@login:~/bin$ qstat | grep XXX.0.par | token.pl 0
1664011
mjeong@login:~/bin$ qstat | grep XXX.0.par | token.pl 1
0.00063

Out of curiosity, is there a standard utility to do this with similar(=simple) interface - so that I don't have to write this little script for any new machine? I understand Awk/Sed can do this, but regex syntax is a little complicated to type every time (I need no brainer syntax, since I use this a lot)

Thanks,

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

cut works exactly the same, with very little addition of complexity

mjeong@login:~/bin$ qstat | grep XXX.0.par | cut -d ' ' -f 1
1664011
mjeong@login:~/bin$ qstat | grep XXX.0.par | cut -d ' ' -f 2
0.00063
share|improve this answer
add comment

The AWK command to do that doesn't require a regular expression, but it can use one to do the grep part, too:

$ qstat | awk '/XXX.0.par/ {print $1}'
1664011
$ qstat | awk '/XXX.0.par/ {print $1}'
0.00063

You can also do this fairly simply in Bash:

$ line=($(qstat | grep XXX.0.par)); echo ${line[0]}
1664011
share|improve this answer
add comment

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.