AWK- extracting values from columns, saving them and gettins statistics


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK- extracting values from columns, saving them and gettins statistics
# 8  
Old 04-13-2011
Quote:
Originally Posted by acsg
Thanks cgkmal! It works Smilie

Now, just to be sure, the outputs could be treated separately by another script, right? I printed them out to a file in a spreadsheet, just to see what they'd look like, and they're both printed in the same column (as opposed to my initial file in which all the fields were in different columns). So I'd just like to know if I could treat them both as separate fields.
Nice that works acsg!

Regarding to your question, I don't know if I completely understand, but yes, you can treat the 2 columns from output as
separated columns (if you use awk each column is represented by $i, in this case column 1=$1 and column 2= $2).
Only depends want you need and is possible to try to get it.

Then, you can handle as you want, to convert them in the input for the spreddsheet graph or just to save them in the spreadsheet itself.


Regards
# 9  
Old 04-15-2011
Quote:
Originally Posted by cgkmal
acsg,

Try with:

Code:
awk '{for(i=4;i<=NF;i=i+2) print $i,$(i+1)}' inputfile


Hope this helps.

Regards
back with a little extra question...
is it possible to print the output in a way that it prints all the lines that contain the same first field, then the next same first field, etc (without doing a sorting based on the second field)?

Example input:

160 1
161 2
162 2
162 3
160 2
160 3
161 3
161 4
161 6
162 1

Desired output:

160 1
160 2
160 3
161 2
161 3
161 4
161 6
162 2
162 3
162 1
# 10  
Old 04-15-2011
Hi acsg,

You can use sort command:

Code:
sort -k1,1n -s inputfile
160 1
160 2
160 3
161 2
161 3
161 4
161 6
162 2
162 3
162 1

See "man sort" and you'll get that:
-k=Option to set the key as sort by field 1
-n=Option to set do a numeric sort
-s=Option to stabilize sort by disabling last-resort comparison

Hope it helps.

Regards
This User Gave Thanks to cgkmal For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Fixed length file extracting values in columns

How do I extract values in a few columns in a row of a fixed length file? If there are 8 columns and I need to extract values of 2nd,4th and 6 th columns, how do i do that? I used cut command, this I used only for one column. How do I do it more than one column? The below command will give... (1 Reply)
Discussion started by: princetd001
1 Replies

2. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the values of two columns (given ranges)

Hi, I have a tab delimited text file with multiple columns. The second and third columns include numbers that have not been sorted. I want to extract rows where the second column includes a value between -0.01 and 0.01 (including both numbers) and the first third column includes a value between... (1 Reply)
Discussion started by: evelibertine
1 Replies

3. Shell Programming and Scripting

Extracting multiple columns with awk

Hi everyone!! I need to apply a simple command to extract columns from a matrix, but I need to extract contemporary from the first to the tenth columns, than from the eleventh to the twentyth and so on... how can i do that? (1 Reply)
Discussion started by: gabrysfe
1 Replies

4. Shell Programming and Scripting

Extracting columns from multiple files with awk

hi everyone! I'd like to extract a single column from 5 different files and put them together in an output file. I saw a similar question for 2 input files, and the line of code workd very well, the code is: awk 'NR==FNR{a=$2; next} {print a, $2}' file1 file2 I added the file3, file4 and... (10 Replies)
Discussion started by: orcaja
10 Replies

5. UNIX for Dummies Questions & Answers

Extracting columns from multiple files with awk

hi everyone! I already posted it in scripts, I'm sorry, it's doubled I'd like to extract a single column from 5 different files and put them together in an output file. I saw a similar question for 2 input files, and the line of code workd very well, the code is: awk 'NR==FNR{a=$2; next}... (1 Reply)
Discussion started by: orcaja
1 Replies

6. Shell Programming and Scripting

extracting columns with awk

Friends, I have a file with fileds in the following order sda 4.80 114.12 128.69 978424 1103384 sdb 0.03 0.40 0.00 3431 0 sda 1.00 0.00 88.00 0 176 sdb ... (14 Replies)
Discussion started by: achak01
14 Replies

7. Shell Programming and Scripting

saving values in file in an array in awk

hi i am trying to save values in a file in an array in awk..the file is as follows: 0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0, so far i have this: awk 'BEGIN {RS="\n";FS=","} { for(i=1;i<=NR;i++) { for(j=1;j<=NF;j++) { a=$j; } } (4 Replies)
Discussion started by: npatwardhan
4 Replies

8. Shell Programming and Scripting

extracting multiple consecutive columns using awk

Hello, I have a matrix 200*10,000 and I need to extract the columns between 40 and 77. I dont want to write in awk all the columns. eg: awk '{print $40, $41, $42,$43 ... $77}'. I think should exist a better way to do this. (10 Replies)
Discussion started by: auratus42
10 Replies

9. Shell Programming and Scripting

saving values from awk expression into shell array

hi i am trying to save the values i extract from a file with the help of awk in a bash shell array. i have: exec 10<file2 while read LINE <&10; do ARRAY1=$(awk '{print $1}' file2) ((count++)) done echo ${ARRAY1} it prints just blank lines. file1 has two columns and i... (4 Replies)
Discussion started by: npatwardhan
4 Replies

10. UNIX for Dummies Questions & Answers

Extracting lines and saving - awk

Hi All, I am trying to extract lines bsed on pattern matching../mp straight-flow/ Extracted output should be saved in meta_string , but the code is not working in that manner,saving repeated lines. can anyone please suggest where am i going wrong. /mp straight-flow/ {... (6 Replies)
Discussion started by: madhaviece
6 Replies
Login or Register to Ask a Question