|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
awk to print first row with forth column and last row with fifth column in each file
file with this content Quote:
Quote:
Code:
awk 'NR==1 {print $4} && NR==2 {print $5}' fileThe error is shown with syntax error; what can be done Quote:
|
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Quote:
Second, we seem to have a language barrier. I do not understand what you want. Are you asking for a script that uses awk to read two lines from a file and write just column 4 from the 1st row and column 5 from the 2nd row? If this is what you want, you can get it using something like: Code:
awk 'NR==1 {print $4}
NR==2 {print $5}' fileAre you asking for a script that reads a file and prints the 1st line that contains 4 or more columns and the 2nd line that contains 5 or more columns? Please show us the output you want from the sample input you provide (in CODE tags) so we more clearly understand what you're trying to do. |
| The Following User Says Thank You to Don Cragun For This Useful Post: | ||
cdfd123 (02-09-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
About how to print: "last row with fifth column; in each file": Code:
END{ print $5 }or in case you are using gawk 4.x: Code:
ENDFILE{ print $5 } |
|
#4
|
||||
|
||||
|
@user8: not every awk retains the fields in the END section. To get around this: Code:
{s=$5} END{ print s } |
| The Following User Says Thank You to Scrutinizer For This Useful Post: | ||
cdfd123 (02-11-2013) | ||
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
You are right. I should have mentioned this.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Print unique names in each row of a specific column using awk | quincyjones | Shell Programming and Scripting | 4 | 12-12-2012 12:23 PM |
| Subtracting each row from the first row in a single column file using awk | ks_reddy | Shell Programming and Scripting | 11 | 04-04-2012 03:31 PM |
| AWK Script - Print a column - within a Row Range | panapty | Shell Programming and Scripting | 6 | 09-28-2011 08:54 AM |
| Moving data from a specified column/row to another column/row | jl487 | Shell Programming and Scripting | 2 | 06-05-2010 12:07 AM |
| Changing the column for a row in a text file and adding another row | aYankeeFan | Shell Programming and Scripting | 9 | 05-02-2005 09:42 PM |
|
|