![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to extract only first column from the file | selamba_warrior | Shell Programming and Scripting | 11 | 05-21-2008 03:52 AM |
| 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 09:57 AM |
| Aggregate values in a file & compare with sql output | shiroh_1982 | UNIX for Dummies Questions & Answers | 1 | 09-02-2007 08:40 AM |
| Extract values from log file | wdympcf | Shell Programming and Scripting | 5 | 08-10-2007 04:52 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I need to extract last column of a file and compare the values
Hi,
I am new to unix and I need help in solving below mentioned issue, really appreciate ur help. I have a file sam, john, 2324, 07142007 tom, thomson, 2343, 07142007 john, scott, 2478, 07142007 its a comma delimited file, I need to extract the last column from each line and this column is a date field. The date should be unique through out the file, if this column has got more than one value, the script should be exited. Please help me out. Thank you |
|
||||
|
returning always 1
Thankx for the reply,
I tested this with duplicate values and also unique muliple values in the column of the file and its always returning 1 data in the file ,,02132007 ,,03132007 script is returning 1 ,,02132007 ,,02132007 here also its retruning 1 if all the column values return unique value out of all the records then I need that unique value in my logic. if it returns more than one value then it should exit with some exit code. can you please modify the script, would be real helpful. I am in urgent need of it. Thanks |
|
||||
|
with duplicate values Code:
cat file sam, john, 2324, 07142007 tom, thomson, 2343, 07142007 john, scott, 2478, 07142007 Code:
awk -F", " '{ arr[$NF]++; for ( i in arr ) { if ( arr[i] > 1 ) { dup=1; exit} } }END{ if ( dup != 1 ) { for ( i in arr ) { print i } } }' file
<< no output >> as there are duplicates without duplicate values Code:
cat file sam, john, 2324, 17142007 tom, thomson, 2343, 27142007 john, scott, 2478, 07142007 the above command returns Code:
07142007 27142007 17142007 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|