Print last 4 columns (variable column #)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Print last 4 columns (variable column #)
# 8  
Old 02-25-2004
Perderabo posted exactly what you wanted.
# 9  
Old 02-25-2004
wow. thanks!
That did it.
# 10  
Old 02-26-2004
Quote:
Originally posted by Da_Duck
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

Perderabo's script would've give you 32 27 from the last row, which is not what you wanted... or did you just make a typo?
# 11  
Old 02-26-2004
Quote:
Originally posted by oombera
Perderabo's script would've give you
32 27 from the last row, which is not
what you wanted... or did you just make a typo?
, that just made me realize that it just won't work with
that feed.

HOWEVER, I do have another feed that it will work on.

Is there any way to search for a row and when found, take the
row after it?

Like this (search for '260454' and retrieve the line after '43 24'):
Code:
260054 CLR                           10          35   7 3213        197
260154 CLR                           10          34   5 3215G20     205
260254 CLR                           10          33   4 3314        212
260354 CLR                           10          31   4 3112        217
260454 CLR                           10          30   4 3212        224
              43  24

# 12  
Old 02-26-2004
To search for lines beginning with '260454' and print the line after
Code:
awk '/^260454/ {getline; print $0}' file1

# 13  
Old 02-26-2004
Works perfect.
Thank you.
# 14  
Old 02-26-2004
why isn't this working?
somehow I cannot set the variable correctly.

My objective is to add the day of the month to 0454
and then search on that.

so I have:
Code:
> echo "`date +'%d0454'`"
260454

then I pipe that to the awk command (but I get no result ...
Code:
echo "`date +'%d0454'`" |  awk -v f1=$1 '/^f1/ {getline; print $0}' test.txt

I get the result when hardcoding it:
Code:
> awk '/^260454/ {getline; print $0}' test.txt
              43  24

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding columns from 2 files with variable number of columns

I have two files, file1 and file2 who have identical number of rows and columns. However, the script is supposed to be used for for different files and I cannot know the format in advance. Also, the number of columns changes within the file, some rows have more and some less columns (they are... (13 Replies)
Discussion started by: maya3
13 Replies

2. Shell Programming and Scripting

awk to Sum columns when other column has duplicates and append one column value to another with Care

Hi Experts, Please bear with me, i need help I am learning AWk and stuck up in one issue. First point : I want to sum up column value for column 7, 9, 11,13 and column15 if rows in column 5 are duplicates.No action to be taken for rows where value in column 5 is unique. Second point : For... (1 Reply)
Discussion started by: as7951
1 Replies

3. Shell Programming and Scripting

awk print columns and variable

Hi, Can anyone help with the below please? I have written some code which takes an input file, and and prints the contents out to a new file - it then loops round and prints the same columns, but increments the ID column by 1 each time. Input file; NAME,1,15-Dec-15, NAME,1,21-Dec-15,... (9 Replies)
Discussion started by: Ads89
9 Replies

4. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Combine columns from many files but keep them aligned in columns-shorter left column issue

Hello everyone, I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble. I have many files each having two columns and hundreds of rows. first column is a string (can have many words) and the second column is a number.The files are... (5 Replies)
Discussion started by: isildur1234
5 Replies

6. Shell Programming and Scripting

Need to find a column from one file and print certain columns in second file

Hi, I need helping in finding some of the text in one file and some columns which have same column in file 1 EG cat file_1 aaaa bbbb cccc dddd eeee fffff gggg hhhh cat file_2 aaaa,abcd,effgh,ereref,name,age,sex,........... bbbb,efdfh,erere,afdafds,name,age,sex.............. (1 Reply)
Discussion started by: jpkumar10
1 Replies

7. Solaris

awk - Print variable number of colums from a starting column

Hi guys, I usualy am able to google awk stuff but I can't find it so far and there are so many awking gurus here that I will give it a shot. I want to print $1;$3;"$5 up to the $NF". In other words, I can have 1000 colums, but need to have $5 up to the end. I started with the idea of... (2 Replies)
Discussion started by: plmachiavel
2 Replies

8. UNIX for Dummies Questions & Answers

How to copy one columns and print to the last column in unix?

I want to copy column no 3 to the end of column example : alter table RECOVER_USR.MPULKIXD rename to alter table RECOVER_USR.CS_ADV_PROMO rename to alter table RECOVER_USR.BCH_HISTORY_TABLE rename to alter table BILLOPS.HISHAM_DATAPLUS_FINAL rename to alter table... (8 Replies)
Discussion started by: arifahel
8 Replies

9. Shell Programming and Scripting

How to check Null values in a file column by column if columns are Not NULLs

Hi All, I have a table with 10 columns. Some columns(2nd,4th,5th,7th,8th and 10th) are Not Null columns. I'll get a tab-delimited file and want to check col by col and generate seperate error code for each col eg:102 if 2nd col value is NULL and 104 if 4th col value is NULL so on... I am a... (7 Replies)
Discussion started by: Mandab
7 Replies

10. Shell Programming and Scripting

can awk print column using a variable ??

i want to print the column file using awk or cut in dynamic manner like trmp=2;temp1=1;temp3=2 awk 'BEGIN{OFS=IFS="\t"} {print $temp,$temp1,$temp3}' client_data.txt or cut -f $temp1,$temp2,$temp3 -d"\t" file_name . but it is showing error , In awk can i use variable as in printing... (36 Replies)
Discussion started by: jambesh
36 Replies
Login or Register to Ask a Question