quick question
Hi,
Just would like to know, How can you get awk to extract first 8 characters, then field $2 with 6 lines into a new file? Or how can awk print $2 with only first 6 lines from that field? |
Eh?
I think you need to elaborate on what constitutes a field for you :} Or, best of, give an example of what you have and what you'd like to get. Cheers, Tink |
I have a field like the one below;
1 2 3 4 5 6 I want to extract the '6' entry into a new file. |
I still don't understand ... to me that's six lines, where's the
field? And, what constitutes a record if 6 is a field? Cheers, Tink |
Sorry,
Well Lets say this is my file $1 $2 01 10 02 20 03 30 04 40 05 50 06 60 Idealy What I want to do is add all the lines together in $2 and extract the total into a new file. |
Quote:
Code:
$1 $2 Cheers, Tink |
I think he means add all the fields in column $2 ... or not ... ;)
|
Yes add all the fields in column $2
10+20+30 etc and extract the total into new file.. |
awk '{ if(NR <7){ sum+=$2 }}END{ print sum }' file > result
And the correct (understandable) question would have been: "How can I add the values of field 2 for the first six lines of a file and save the result to a separate file?" Cheers, Tink |
Cheers Tink
|
Ok lets say, the format of the file is exactly like the one below. My question would be how can you do the same process as above but all results for the first six lines are saved into same separate file?
$2 10 20 30 40 50 60 10 20 30 40 50 60 20 30 40 50 60 70 So the output of the result file would look something like; 180 180 240 |
Every file can only have one set of "first 6 lines" ;} ...
You're talking about records this time, and the records are separated by one or more empty lines. man awk /RS is a good starting point, you can use what I provided above as a starting point. :} Cheers, Tink |
Yeh records are separated by one empty line. And they are always 6 lines long. As specified in previous post.
|
I have looked at the awk man, there aren't any specific examples that I can relate to? So not sure how to preform it.
|
Code:
awk 'BEGIN{RS="";FS="\n";OFS="\n\n"} ... Cheers, Tink |
All times are GMT -5. The time now is 04:45 AM. |