![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is the difference between f(...), f(void) and f() | purplelightspar | High Level Programming | 2 | 04-29-2008 09:34 AM |
| regarding file sorting | phani_sree | High Level Programming | 1 | 02-02-2007 12:04 PM |
| Sorting a file | Khoomfire | Shell Programming and Scripting | 2 | 12-13-2005 04:48 AM |
| Help sorting file. | gio123bg | Shell Programming and Scripting | 3 | 12-10-2003 07:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Sorting the Void File in CSH
First and foremost, this is not a homework for your information. I'm just new to using c-shell programming and I just wanted to make my life easier @ work.
Say, the file contains the following: Code:
ID FILE NO. SL VP 1 1 22 33 1 2 22 33 2 3 33 44 3 4 33 55 4 5 44 55 4 6 44 55 4 7 44 55 3 8 33 55 5 9 77 88 The First, Third and Fourth Fields of Rows (1 & 2) are repeated and so with Rows (4 & 8) and Rows (5, 6 & 7). I want my csh script to check for void File No. If the first, second and third fields are repeated, the former shows me the void file/s. In this example, File Nos. 1, 4, 5 and 6 are void. File 2 is the good file and so with File 7 & 8. Files 3 & 9 are good files as well since they are not repeated. Thanks in Advance. Last edited by Perderabo; 11-03-2005 at 02:42 PM. Reason: add code tags for readability |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
From the above example, I was able to extract the rows that are not repeated on the line.
awk '{print substr($0,6,5)}' $SOLHOME/internalDisk/2 | sort -k1,2 | uniq -d Result: 22 33 33 55 44 55 How do I compare this result now from the original file to show me the FILE NO. of the repeated rows except the last line of these rows? |
|
#3
|
|||
|
|||
|
Hello Gentlemen!
I'm new to Csh script programming and I have not really attended any formal unix training course whatsoever. I'd really been trying hard to solve the above example but to no avail. I tried using "foreach" but I'm not really sure how this command works. I've read the man foreach but it didn't give much help either. Could someone please give me an input? Thanks a lot.... |
|
#4
|
||||
|
||||
|
I can't recommend using csh for shell programming. See this article: Csh Programming Considered Harmful.
Your problem can be solved using awk.... Code:
awk '{a[$1,$3,$4]++;b[$1,$3,$4]=$0}END{for(x in a)if(a[x]==1)print b[x]}' file
Code:
ID FILE NO. SL VP 5 9 77 88 2 3 33 44 |
||||
| Google The UNIX and Linux Forums |