Need help with awk to get values from input (newbie here)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help with awk to get values from input (newbie here)
# 8  
Old 11-19-2011
Sorry -- Thought I posted something ealrier; must have hit preview instead of submit. I suggested a small tweek to get some extra debug info out:

Code:
awk '{ 
print;   # debug output of each line
for( i=2; i <= NF; i += 2 ) 
   printf( "%d ", $(i) ); 
printf( "\n" ); 
}' processes.txt

If you could post the first 6 or 8 lines of output it'd be interesting to see what is going on.
# 9  
Old 11-20-2011
hi!

sure here it is!

Code:
bash-3.00$ awk '{ 
> print;   # debug output of each line
> for( i=2; i <= NF; i += 2 ) 
>    printf( "%d ", $(i) ); 
> printf( "\n" ); 
> }' processes.txt
ID: 35; Arrival_Time: 0; Total_Exec_Time: 4; 
0 0 0 
ID: 65; Arrival_Time: 2; Total_Exec_Time: 6; 
0 0 0 
ID: 10; Arrival_Time: 3; Total_Exec_Time: 3; 
0 0 0 
ID: 124; Arrival_Time: 5; Total_Exec_Time: 5; 
0 0 0 
ID: 182; Arrival_Time: 6; Total_Exec_Time: 2; 
0 0 0

# 10  
Old 11-20-2011
Ok, I'm stumped. I cut and pasted both your code and data and this is the output on both gnu awk version 3.1.6 and FreeBSD awk version 20091126 is the same and what I expected:

Code:
ID: 35; Arrival_Time: 0; Total_Exec_Time: 4; 
35 0 4 
ID: 65; Arrival_Time: 2; Total_Exec_Time: 6; 
65 2 6 
ID: 10; Arrival_Time: 3; Total_Exec_Time: 3; 
10 3 3 
ID: 124; Arrival_Time: 5; Total_Exec_Time: 5; 
124 5 5 
ID: 182; Arrival_Time: 6; Total_Exec_Time: 2; 
182 6 2

Next question... are you running on Solaris? If so use nawk instead of awk. If not try this (grasping for straws now):
Code:
awk '{ 
 gsub( ";", "", $0 ); 
 for( i=2; i <= NF; i += 2 ) 
    printf( "%d ", $(i) ); 
 printf( "\n" ); 
 }'  input-file

# 11  
Old 11-20-2011
agama's latest one with gsub should work...
Try this with a small modification...
Code:
awk '{
print;   # debug output of each line
for( i=2; i <= NF; i += 2 ) 
   printf( "%d ", $i+0 ); 
printf( "\n" ); 
}' processes.txt

BTW, everything works for me too... Smilie
--ahamed
# 12  
Old 11-21-2011
im using secure shell client to connect to my school's afs thingy
# 13  
Old 11-21-2011
Quote:
Originally Posted by mehungry
im using secure shell client to connect to my school's afs thingy
What is the output of these commands:
Code:
uname -a
awk --version

# 14  
Old 11-21-2011
hey!

the output of uname -a is:

Code:
SunOS *this part has my school's server address idk if I should leave that in here lol* 5.10 Generic_142900-02 sun4u sparc SUNW,Sun-Fire-280R

nothing happens when I type awk --version Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

User input and run awk using the input

I am trying to allow a user to enter in text and then store that text in a variable $gene to run in an awk command in which those values are used to run some calculations. I am getting syntax errors however, when I try. Thank you :). The awk runs great if it is a pre-defined file that is used,... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

awk file to read values from Db2 table replacing hard coded values

Hi, I want to replace a chain of if-else statement in an old AWK file with values from Db2 table or CSV file. The part of code is below... if (start_new_rec=="true"){ exclude_user="false"; user=toupper($6); match(user, "XXXXX."); if (RSTART ==2 ) { ... (9 Replies)
Discussion started by: asandy1234
9 Replies

3. Shell Programming and Scripting

Capturing multiple values from user input

Hello, I need to capture multiple values from user input and do not know how to do it. I'm writing a script to delete old files, but want to give the option to keep some by asking the user. This is what my output looks like... Old files to be deleted... 1 file1 2 file2 Then this bit of... (3 Replies)
Discussion started by: jrymer
3 Replies

4. Shell Programming and Scripting

Splitting record into multiple records by appending values from an input field (AWK)

Hello, For the input file, I am trying to split those records which have multiple values seperated by '|' in the last input field, into multiple records and each record corresponds to the common input fields + one of the value from the last field. I was trying with an example on this forum... (4 Replies)
Discussion started by: imtiaz99
4 Replies

5. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

6. Shell Programming and Scripting

Newbie help needed for comparing values

Being linux administrator my task is to keep the machines up and running .Everyday i get a report of list of machines that are up and running. it would be nice if i get list of machines that are shutdown in comparison to yesterdays report. for example.If there are 5 machines in my environment... (5 Replies)
Discussion started by: pinga123
5 Replies

7. Shell Programming and Scripting

Input new values into a column

Hi I would like to change certain columns in a file depending on the users choice of input and which columns they would like to change. Here is my csv file: SITEID,CELLID,Access Grant Blocks Reserved 1,1A,5 1,1B,2 1,1C,3 2,2A,7 2,2B,4 2,2C,0 If for example they would... (9 Replies)
Discussion started by: ladyAnne
9 Replies

8. Shell Programming and Scripting

AWK: read values from file1; search for values in file2

I have read another post about this issue and am wondering how to adapt it to my own, much simpler, issue. I have a file of user IDs like so: 333333 321321 546465 ...etc I need to take each number and use it to print records wherein the 5th field matches the user ID pulled from the... (2 Replies)
Discussion started by: Bubnoff
2 Replies

9. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

10. Shell Programming and Scripting

How to validate input values

Hi How would i validate value of a variable whether it is number,date or string Thanks in advance Sas (5 Replies)
Discussion started by: SasDutta
5 Replies
Login or Register to Ask a Question