One of the awk column spilling on the new line from beginning


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting One of the awk column spilling on the new line from beginning
# 1  
Old 08-26-2013
One of the awk column spilling on the new line from beginning

I am having a problem where the Compute field/column is spilling over to the new line. Here's the piece of code and the o/p:-

Code Sniplet:-
Code:
for id in `qstat -u "*" -q "$Queue" -s r |sed -n '3,$ p'|awk -F" " '{print $1}'`
do
NODELIST=`cat /scratch/$id.hostlist.*|awk -F" " '{print $1,$2}'|tr ' ' '*'|sed ':a;N;$!ba;s/\n/,/g'`
NODES=`cat /scratch/$id.hostlist.*|awk -F" " '{print $1}'|wc -l`
echo -ne "$id $NODES $NODELIST\n" >> "$TMPFILE2"
done
cat "$TMPFILE2"|awk -F" " 'BEGIN { printf "%-15s %-15s %s\n","JOBID","NDS","COMPUTE"
printf "%-15s %-15s %s\n","-----","-----","-----"}
{ printf "%-15s %-15s  %s\n",$1,$2,$3 }'

output:-
Code:
JOBID NDS COMPUTE
----- ----- -----
4884 32 n264*1,n246*1,n263*1,n270*1,n269*1,n249*1,n258*1,n242*1,n271*1,n383*1,n151*1,n156*1,n160*1,n161*1,n1 62*1,163*1,n164*1,n165*1,n166*1,n167*1,n168*1,n173*1,n385*1,n377*1,n183*1,n184*1,n185*1,n189*1,n192* 1,n194*1,n195*1,n196*1
5034 2 n305*4,n308*4

Expected o/p :- Want to align Compute node data which are spilling onto new line and are beginning from start
output:-
Code:
JOBID NDS COMPUTE
----- ----- -----
4884 32 n264*1,n246*1,n263*1,n270*1,n269*1,n249*1,n258*1,n242*1,n271*1,n383*1,n151*1,n156*1,n160*1,n161*1,n1
            62*1,163*1,n164*1,n165*1,n166*1,n167*1,n168*1,n173*1,n385*1,n377*1,n183*1,n184*1,n185*1,n189*1,n192* 1,n194*1,n195*1,n196*1


Last edited by Scrutinizer; 08-26-2013 at 03:52 AM.. Reason: additional code tags
# 2  
Old 08-26-2013
This probably is a terminal artefact. What be your COLUMNS value? Try printing to a file and view that with an editor or a pager.

If you really want awk print the $3 value in a second line, you need to split it, and print the second part in a second printf statement with two empty dummies in front.
# 3  
Old 08-27-2013
Hello RudiC, sorry I think I got you a bit confused with my question. Here's the o/p which I am currently getting.

Quote:
5101 45 [[n31*8,n35*8,n305*8,n308*8,n34*8,n30*8,n29*8,n325*8,n62*8,n321*8,n63*8,n61*8,n64*8,n332*8,n57*8,n44*8 ,n66*8,n315*8,n65*8,n318*8,n47*8,n334*8,n42*8,n336*8,n330*8,n335*8,n328*8,n121*8,n369*8,n338*8,n113* 8,n340*8,n341*8,n366*8,n116*8,n128*8,n348*8,n357*8,n32*8,n359*8,n138*8,n347*8,n139*8,n363*8,n356*8]]
I want my third column(Compute) where lines are long and are spilling to next line and beginning from the start of next line to be *indented to the compute column*. I guess this is something to do with formatting of the third column. I just wanted to know if there is any possibility to make this happen via awk.
# 4  
Old 08-27-2013
Did you read/understand my second paragraph?
# 5  
Old 08-28-2013
RudiC, I have tried with the split function in awk and I think I am getting the desired o/p. With just some fine tuning I will be able to get the exact output. Thank you very much.
# 6  
Old 08-28-2013
You can split it, or you can use the substr function.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Insert a column in the beginning

Hi, I have been trying to see how i can insert a column in the beginning to my html table This is how it looks Name Age Sid 32 John 33 Mary 34 I want to insert a column Job before Name column, so it looks like Job Name Age IT Sid 32 Doctor... (3 Replies)
Discussion started by: sidnow
3 Replies

2. Shell Programming and Scripting

comment a line of the patterns is a the beginning of the line

I need to comment the lines starting with pattern "exclude" or "exclude=". If the work exclude comes at any other part, ignore it. Also, ignore, excludes, excluded etc. Ie only comment the line starting with exclude. File contents. exclude exclude= hi I am excluded excludes excludes= ... (9 Replies)
Discussion started by: anil510
9 Replies

3. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

4. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

5. Shell Programming and Scripting

awk , conditional involving line and column

Dear All, I indeed your help for managing resarch data file. for example I have, data1.txt : type of atoms z vz Si 34 54 O 20 56 H 14 13 Si 40 17 O ... (11 Replies)
Discussion started by: ariesto
11 Replies

6. Shell Programming and Scripting

Awk next line as column

Hi, This forum rocks. I think this might be an easy thing, but since I am new to awk, please help me. input: x y z 1 a b c 2 d e f 3 g h i 7 output: x y z 1 a b c 2 d e f 3 (8 Replies)
Discussion started by: jacobs.smith
8 Replies

7. Shell Programming and Scripting

Counting rows line by line from a specific column using Awk

Dear UNIX community, I would like to to count characters from a specific row and have them displayed line-by-line. I have a file called testAwk2.csv which contain the following data: rabbit penguin goat giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Discussion started by: vnayak
4 Replies

8. Shell Programming and Scripting

awk convert from line to column

i have an output like this : 012008 25760883 022008 12273095 032007 10103 032008 10115642 042007 20952798 but i would like to have it like this 012008,25760883 022008,12273095 032007,10103 032008,10115642 042007,20952798 (4 Replies)
Discussion started by: jarmouda
4 Replies

9. Shell Programming and Scripting

line to column using awk

hi, i'm a newbie and this is my first post here. 'hope all of you fellow members are doing fine. so here is my first thread to ask for help on how to use awk language to do this task. i have a file to process and after a series of other awk commands and shell scripts i managed to convert the... (11 Replies)
Discussion started by: genix2008
11 Replies

10. Shell Programming and Scripting

Unix Script with line number at beginning of each line.

Could anybody help me. I need to create a script that reads a text file from STDIN and prints out the file to STDOUT with line numbers at the beginning of each line. Thanks. (5 Replies)
Discussion started by: mascorro
5 Replies
Login or Register to Ask a Question