![]() |
|
|
|
|
|||||||
| 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 |
| Break a file into separate files | chiru_h | Shell Programming and Scripting | 8 | 07-29-2008 12:06 AM |
| File names based off of wildcards | tcquad | UNIX for Dummies Questions & Answers | 1 | 01-30-2008 02:51 PM |
| Output of command to 2 separate file? | TheCrunge | UNIX for Dummies Questions & Answers | 2 | 12-08-2005 01:45 PM |
| Separate a portion of text file into another file | srikanth_ksv | Shell Programming and Scripting | 4 | 08-05-2005 05:11 AM |
| Listing words from a file on a Separate Line | Astudent | UNIX for Dummies Questions & Answers | 2 | 03-14-2001 03:44 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Separate based on file names
Hello experts,
This might prove to be a stupid question to some of you, but I have tried to tackle it in different ways. Being new to shell scripting, I am requesting your help in coming up with an elegant solution. I am using Korn shell. We have a directory with file names with the pattern: abc_123 abc_456 xyz_789 I have to compare them against a prefix file to check whether the names behind the underscore are valid and consolidate them in different directories. How do I do that? 1. Put them in different files and use diff/comm to compare. This requires multiple passes - since the consolidation is more than what I can highlight here. 2. Do something like: FileList=$(ls -r $SOURCE_DIR) # list & sort PrefixList=$(cat $PREFIX_FILE | sort -r) for sFile in $sFileList do iDelimit=$(expr index $sFile _) (( iDelimit -= 1 )) sFileCmp=$(expr substr $sFile 1 $iDelimit) for sPrefix in $sPrefixList do echo $sFileCmp compared with $sPrefix if [ $sFileCmp -gt sPrefix ] # will not work, symbolic then continue elif [ $sFileCmp -eq sPrefix ] then blPrefixValid=1 else blPrefixValid=0 break fi done 3. Get valid prefixes and run through the directory each time to process files Any help appreciated. Thanks. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Quote:
Thanks Nagarajan G |
|
#3
|
|||
|
|||
|
Thanks for your reply.
The prefix is the criteria. If the file has valid prefix (that can be found in the prefix list) - that goes in one directory, if it is a duplicate it goes in the other and so on. |
|||
| Google The UNIX and Linux Forums |