jhapk
May 15, 2010, 1:48pm
1
Hi,
for a particular system, the command $qstat -f gives me an output of the syntax:
<many lines of text>
PBS_DIR = <address of a dir>
<sometimes when address is long, it is broken in 2 lines>
<many lines of text>
When I do $qstat -f | grep PBS_DIR, I only get one line containing the address. It works fine when the output is the following format:
<many lines of text>
PBS_DIR=/home/user/scratch/bluffbody/mixing/k_omega_1998/g2,
PBS_O_QUEUE=batch
<many lines of text>
But sometimes the address continues in two lines, for example:
<many lines of text>
PBS_DIR=/home/user/scratch/bluffbody/hot/pcmfpi/k_omega_1998
/ss_on/g2,PBS_O_QUEUE=batch
<many lines of text>
For the last case, grep doesn't give me the right address. How can I output the right directory path?
Thanks
Using sed can do that.
But you need to have a tangible sign that tells you when a line is the continuation of the previous one.
For example in shell script, if a line finishes with \, it means we have to join the next line.
In your example how will your command tell that /ss_on/g2,PBS_O_QUEUE=batch is actually part of the previous line?
How about ...
[house@leonov] cat test.file | sed ':a; $!N;s/\n *\//\//;ta;P;D'
<many lines of text>
PBS_DIR=/home/user/scratch/bluffbody/mixing/k_omega_1998/g2,
PBS_O_QUEUE=batch
<many lines of text>
<many lines of text>
PBS_DIR=/home/user/scratch/bluffbody/hot/pcmfpi/k_omega_1998/ss_on/g2,PBS_O_QUEUE=batch
<many lines of text>
[house@leonov] cat test.file | sed ':a; $!N;s/\n *\//\//;ta;P;D' | grep -E -o 'PBS_DIR.*,'
PBS_DIR=/home/user/scratch/bluffbody/mixing/k_omega_1998/g2,
PBS_DIR=/home/user/scratch/bluffbody/hot/pcmfpi/k_omega_1998/ss_on/g2,
(Reference )