|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Awk to find space and tab.
Wants to print line when there exist leading or trailing space or tab in fields 2,3 and 5 The below code prints all lines in file even if they dont have leading and trailing space or tab. Code:
nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^[ \t]*" || $i ~ "[ \t]*$")}}1' filefile Quote:
Quote:
|
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Change the * to +. You have made the extremely common mistake of using an REGEX with a zero length match.
|
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Quote:
Code:
nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^[ \t]+" || $i ~ "[ \t]+$")}}1' filestill the same thing. And i want to look 2,3 and 5th field only not all the fields |
|
#4
|
||||
|
||||
|
Yes, but you also have a '1' there, so you are printing every line. You need to delete that too, any you do nothing in the for loop/if statement.
Just check the field number in the for lop and print out the lines you want. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
The below code returns nothing. Code:
nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^[ \t]+" || $i ~ "[ \t]+$")}}' fileHelp appreciated |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
But would like to remove sort -u and handle it with in awk Code:
nawk -F"|" '{for(i=1;i<=NF;i++) {if ($i ~ "^[ \t]+" || $i ~ "[ \t]+$") print $0}}' file |
sort -u > outfile |
| 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 |
| for i in `find *` breakdown since the directory name has space | patiobarbecue | Shell Programming and Scripting | 3 | 12-09-2008 10:44 AM |
| How to find the free space & usage of the particular directory in Hp-Unix? | bobprabhu | UNIX for Dummies Questions & Answers | 2 | 06-27-2008 01:05 PM |
| Find lines with space between strings | Galt | Shell Programming and Scripting | 5 | 05-07-2008 02:06 PM |
| How to find the top 6 users (which consume most space)? | RebelDac | AIX | 5 | 09-17-2007 06:36 PM |
| How to find the size of Process Address space. | S.Vishwanath | UNIX for Dummies Questions & Answers | 1 | 07-10-2001 08:46 AM |
|
|