The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert two column data into 8 columns NickC Shell Programming and Scripting 8 06-28-2008 08:19 AM
how to read the column and print the values under that column gemini106 Shell Programming and Scripting 6 03-28-2008 04:05 AM
Single column to multiple columns in awk astroDave Shell Programming and Scripting 2 03-27-2008 07:00 PM
How to check Null values in a file column by column if columns are Not NULLs Mandab Shell Programming and Scripting 7 03-15-2008 06:57 AM
can awk print column using a variable ?? jambesh Shell Programming and Scripting 36 09-26-2006 04:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-25-2004
Registered User
 

Join Date: Feb 2004
Posts: 16
Print last 4 columns (variable column #)

I have rows of data with variable number of columns.

Is there an easy way to print out the last 4 columns
or rather the 4th and 3rd last column?

data looks like this:
Code:
           24 20:51 N 9 10.00 Overcast OVC110 27 11 30.04 1017.7
         24 19:51 N 7 10.00 Mostly Cloudy BKN110 28 15 30.03 1017.2
      24 18:51 N 5 10.00 Partly Cloudy FEW080 SCT100 29 14 32 27 30.02 1017.0
I need:
Code:
27 11
28 15
14 32
__________________
- The_Duck
Reply With Quote
Forum Sponsor
  #2  
Old 02-25-2004
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
i am sure you could but useing awk could prove a bit difficult since your colums never line up (assumeing you had a space as a field seperator)

your looking at a full fledged program since each line could be differant.

if you could put a field seperator into your data it would be extreamly easy to get the parts you want.
Reply With Quote
  #3  
Old 02-25-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
How about: awk '{print $(NF-3), $(NF-2)}'
Reply With Quote
  #4  
Old 02-25-2004
Registered User
 

Join Date: Feb 2004
Posts: 16
I can do that.
What if I delimit with a pipe?
Does that help?

lynx -dump "http://www.crh.noaa.gov/data/obhistory/KALB.html" | grep "24 " | awk {'print $1 "|" $2 "|" $3 "|" $4 "|" $5 "|" $6 "|" $7 "|" $8 "|" $9 "|" $10 "|" $11 "|" $12 "|" $13 "|" $14'}

Code:
24|23:51|N|9|10.00|Fair|CLR|21|5|30.09|1019.3|||
24|22:51|N|5|10.00|Fair|CLR|22|7|30.08|1019.0|||
24|21:51|N|8|10.00|Fair|CLR|24|9|30.06|1018.3|||
24|20:51|N|9|10.00|Overcast|OVC110|27|11|30.04|1017.7|||
24|19:51|N|7|10.00|Mostly|Cloudy|BKN110|28|15|30.03|1017.2||
24|18:51|N|5|10.00|Partly|Cloudy|FEW080|SCT100|29|14|32|27|30.02
24|17:51|NE|7|10.00|Overcast|OVC100|29|16|30.01|1016.6|||
24|16:51|E|6|10.00|Overcast|OVC100|31|18|30.01|1016.5|||
24|15:51|E|6|10.00|A|Few|Clouds|FEW080|31|16|30.01|1016.7|
24|14:51|Vrbl|3|10.00|Overcast|BKN075|OVC090|32|17|30.02|1017.1||
24|13:51|NE|3|10.00|Overcast|BKN080|OVC090|30|16|30.05|1018.0||
24|12:51|Calm|10.00|Mostly|Cloudy|BKN080|28|15|28|20|30.08|1019.1|
24|11:51|Vrbl|3|10.00|Fair|CLR|26|14|30.11|1019.9|||
24|10:51|N|7|10.00|Fair|CLR|25|13|30.12|1020.2|||
24|09:51|N|7|10.00|Mostly|Cloudy|BKN085|24|14|30.13|1020.6||
24|08:51|N|6|10.00|Mostly|Cloudy|BKN090|22|15|30.13|1020.8||
24|07:51|N|6|10.00|Overcast|OVC090|20|15|30.15|1021.4|||
24|06:51|N|5|10.00|Overcast|BKN100|OVC120|20|15|24|19|30.14|1021.2
24|05:51|N|5|10.00|A|Few|Clouds|FEW100|20|14|30.14|1021.2|
24|04:51|N|7|10.00|Fair|CLR|21|14|30.14|1021.1|||
24|03:51|N|3|10.00|A|Few|Clouds|FEW100|21|14|30.15|1021.3|
24|02:51|N|5|10.00|Fair|CLR|22|14|30.16|1021.6|||
24|01:51|N|5|10.00|Fair|CLR|22|14|30.17|1022.1|||
24|00:51|N|7|10.00|Fair|CLR|24|15|32|24|30.17|1021.9|
__________________
- The_Duck
Reply With Quote
  #5  
Old 02-25-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
If you're gonna do that, just print the one or two fields that you need. It's crazy to print all the fields, then look for a way to strip most of them off...
Reply With Quote
  #6  
Old 02-25-2004
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Quote:
Originally posted by Perderabo
How about: awk '{print $(NF-3), $(NF-2)}'
Perderabo lays the smack down shows how easy it is for an old pro.

Code:
NF    number of fields in the current record
Reply With Quote
  #7  
Old 02-25-2004
Registered User
 

Join Date: Feb 2004
Posts: 16
Quote:
Originally posted by Perderabo
If you're gonna do that, just print the one or two fields that you need. It's crazy to print all the fields, then look for a way to strip most of them off...
This is what I am asking.
Due to the variable column number in each row
I am having trouble figuring out how to do this.

Basically I want the highest number from one column
and the lowest from the other.

I'll bold the two columns I am interested in.

Code:
24 20:51 N 9 10.00 Overcast OVC110 27 11 30.04 1017.7
24 19:51 N 7 10.00 Mostly Cloudy BKN110 28 15 30.03 1017.2
24 18:51 N 5 10.00 Partly Cloudy FEW080 SCT100 29 14 32 27 30.02 1017.0
__________________
- The_Duck
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:57 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0