LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-22-2009, 12:29 AM   #1
abhigrkist
LQ Newbie
 
Registered: Sep 2008
Posts: 8

Rep: Reputation: 0
how to find a file with uniq extension


Hi ,

I have one file called “ab” in below path. That file contains so many no of file with dot extensions.

cat ab
crank.ini
lion.DAT
tiger.bad
unix.txt
linux.ini
abhi.DAT
P.bad
del.bhabani
avatar.film
KNPH.film
sri.txt
suc.com
loh.txt
ama.com



Please tell me how can I knw only uniq .extensions??
 
Old 12-22-2009, 12:50 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,531
Blog Entries: 27

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
What have you thought of and tried so far?

Your question is ambiguous. Do you mean that you are given extension ".ab" and you want to know if it is unique or you want to generate a list of extensions that are unique. By "unique" do you mean unique in the current directory, current file system, computer, network ...? The first step to solving a problem is to know exactly what the problem is!
 
Old 12-22-2009, 01:17 AM   #3
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
Code:
#!/bin/bash

while read f ;
do
#	echo $f;
	echo ${f##*.} >> extensions
done <ab

sort extensions  | uniq -u -i>extension3
i think he needs to know the unique extensions in the file
extension3 will have the unique extensions,i think
 
Old 12-22-2009, 01:35 AM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Code:
$ awk -F"." '!a[$NF]++{print $NF}' file
ini
DAT
bad
txt
bhabani
film
com

Last edited by ghostdog74; 12-22-2009 at 02:07 AM.
 
Old 12-22-2009, 01:38 AM   #5
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
Can you explain the code??
 
Old 12-22-2009, 02:16 AM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Code:
$ awk -F"." 'a[$NF]++{print $NF,a[$NF]}' file
ini 2
DAT 2
bad 2
film 2
txt 2
txt 3
com 2
the above says, store the extension in associative array "a", and increment its value each time its found and stored.

Code:
$ awk -F"." '!a[$NF]++{print $NF,a[$NF]}' file
ini 1
DAT 1
bad 1
txt 1
bhabani 1
film 1
com 1
By putting "!" operator in front, and since "!" precedence is higher than ++, it just says those extension that are "not" already in array, store it. Skip it if its already in array.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use uniq on first part of file but print whole line. snowman81 Programming 4 10-03-2009 06:22 AM
Linux file extension vs Dos file Extension? manaa Linux - Newbie 6 02-12-2009 04:19 PM
bash: renaming file extension based on actual file type alekone Linux - General 9 12-28-2008 09:12 AM
why when redirecting output to a file any file extension seems to be fine? dr_zayus69 Linux - General 1 05-21-2005 04:09 AM
Where to find documentation about ``X Shape Extension''? unsigned_nerd Linux - Software 0 01-08-2005 10:21 AM


All times are GMT -5. The time now is 06:43 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration