xargs plus shell string manipulation vs sed [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













This question already has an answer here:



  • recursive statistics on file types in directory?

    4 answers



I am trying to summarise the file extensions in a directory recursively.



find .| xargs -d "n" -I@ echo "$@##.*" | sort |uniq -c



But this is giving me a series of blank lines. Not what I wanted.



I am aware of:



find . -type f | sed 's/.*.//' | sort | uniq -c from a similar question, but am curious about why my formulation doesn't work.










share|improve this question















marked as duplicate by don_crissti, Goro, Jeff Schaller, Kusalananda shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • What are you trying to accomplish : are you trying to summarize file types based on mime types or based on extensions (these are two different things) ?
    – don_crissti
    yesterday










  • @Goro for a medium-sized directory I receive -bash: /usr/bin/file: Argument list too long
    – Tim
    yesterday











  • @don_crissti I'd like to know how to use both methods. I realise there are differences, and prefer the mime types. If the file command is taking too long, I'd revert to extension-based type.
    – Tim
    yesterday










  • ... if you want the mime types then find . -type f -exec file --brief --mime-type ; | sort | uniq -c should do. Your code also works if you use a for loop, e.g. for f in **/*; do...
    – don_crissti
    yesterday











  • @Tim what is the objective of the process, I mean what you would like to achieve by the end, more specifically why you are using cut sort and uniq? The commands seems to be meaningless in providing correct output for cut and sort. If you would please provide example of the desired output this will be very helpful for us to help
    – Goro
    yesterday















up vote
0
down vote

favorite













This question already has an answer here:



  • recursive statistics on file types in directory?

    4 answers



I am trying to summarise the file extensions in a directory recursively.



find .| xargs -d "n" -I@ echo "$@##.*" | sort |uniq -c



But this is giving me a series of blank lines. Not what I wanted.



I am aware of:



find . -type f | sed 's/.*.//' | sort | uniq -c from a similar question, but am curious about why my formulation doesn't work.










share|improve this question















marked as duplicate by don_crissti, Goro, Jeff Schaller, Kusalananda shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • What are you trying to accomplish : are you trying to summarize file types based on mime types or based on extensions (these are two different things) ?
    – don_crissti
    yesterday










  • @Goro for a medium-sized directory I receive -bash: /usr/bin/file: Argument list too long
    – Tim
    yesterday











  • @don_crissti I'd like to know how to use both methods. I realise there are differences, and prefer the mime types. If the file command is taking too long, I'd revert to extension-based type.
    – Tim
    yesterday










  • ... if you want the mime types then find . -type f -exec file --brief --mime-type ; | sort | uniq -c should do. Your code also works if you use a for loop, e.g. for f in **/*; do...
    – don_crissti
    yesterday











  • @Tim what is the objective of the process, I mean what you would like to achieve by the end, more specifically why you are using cut sort and uniq? The commands seems to be meaningless in providing correct output for cut and sort. If you would please provide example of the desired output this will be very helpful for us to help
    – Goro
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:



  • recursive statistics on file types in directory?

    4 answers



I am trying to summarise the file extensions in a directory recursively.



find .| xargs -d "n" -I@ echo "$@##.*" | sort |uniq -c



But this is giving me a series of blank lines. Not what I wanted.



I am aware of:



find . -type f | sed 's/.*.//' | sort | uniq -c from a similar question, but am curious about why my formulation doesn't work.










share|improve this question
















This question already has an answer here:



  • recursive statistics on file types in directory?

    4 answers



I am trying to summarise the file extensions in a directory recursively.



find .| xargs -d "n" -I@ echo "$@##.*" | sort |uniq -c



But this is giving me a series of blank lines. Not what I wanted.



I am aware of:



find . -type f | sed 's/.*.//' | sort | uniq -c from a similar question, but am curious about why my formulation doesn't work.





This question already has an answer here:



  • recursive statistics on file types in directory?

    4 answers







shell sed xargs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 50 mins ago

























asked yesterday









Tim

1535




1535




marked as duplicate by don_crissti, Goro, Jeff Schaller, Kusalananda shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by don_crissti, Goro, Jeff Schaller, Kusalananda shell
Users with the  shell badge can single-handedly close shell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
yesterday


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • What are you trying to accomplish : are you trying to summarize file types based on mime types or based on extensions (these are two different things) ?
    – don_crissti
    yesterday










  • @Goro for a medium-sized directory I receive -bash: /usr/bin/file: Argument list too long
    – Tim
    yesterday











  • @don_crissti I'd like to know how to use both methods. I realise there are differences, and prefer the mime types. If the file command is taking too long, I'd revert to extension-based type.
    – Tim
    yesterday










  • ... if you want the mime types then find . -type f -exec file --brief --mime-type ; | sort | uniq -c should do. Your code also works if you use a for loop, e.g. for f in **/*; do...
    – don_crissti
    yesterday











  • @Tim what is the objective of the process, I mean what you would like to achieve by the end, more specifically why you are using cut sort and uniq? The commands seems to be meaningless in providing correct output for cut and sort. If you would please provide example of the desired output this will be very helpful for us to help
    – Goro
    yesterday

















  • What are you trying to accomplish : are you trying to summarize file types based on mime types or based on extensions (these are two different things) ?
    – don_crissti
    yesterday










  • @Goro for a medium-sized directory I receive -bash: /usr/bin/file: Argument list too long
    – Tim
    yesterday











  • @don_crissti I'd like to know how to use both methods. I realise there are differences, and prefer the mime types. If the file command is taking too long, I'd revert to extension-based type.
    – Tim
    yesterday










  • ... if you want the mime types then find . -type f -exec file --brief --mime-type ; | sort | uniq -c should do. Your code also works if you use a for loop, e.g. for f in **/*; do...
    – don_crissti
    yesterday











  • @Tim what is the objective of the process, I mean what you would like to achieve by the end, more specifically why you are using cut sort and uniq? The commands seems to be meaningless in providing correct output for cut and sort. If you would please provide example of the desired output this will be very helpful for us to help
    – Goro
    yesterday
















What are you trying to accomplish : are you trying to summarize file types based on mime types or based on extensions (these are two different things) ?
– don_crissti
yesterday




What are you trying to accomplish : are you trying to summarize file types based on mime types or based on extensions (these are two different things) ?
– don_crissti
yesterday












@Goro for a medium-sized directory I receive -bash: /usr/bin/file: Argument list too long
– Tim
yesterday





@Goro for a medium-sized directory I receive -bash: /usr/bin/file: Argument list too long
– Tim
yesterday













@don_crissti I'd like to know how to use both methods. I realise there are differences, and prefer the mime types. If the file command is taking too long, I'd revert to extension-based type.
– Tim
yesterday




@don_crissti I'd like to know how to use both methods. I realise there are differences, and prefer the mime types. If the file command is taking too long, I'd revert to extension-based type.
– Tim
yesterday












... if you want the mime types then find . -type f -exec file --brief --mime-type ; | sort | uniq -c should do. Your code also works if you use a for loop, e.g. for f in **/*; do...
– don_crissti
yesterday





... if you want the mime types then find . -type f -exec file --brief --mime-type ; | sort | uniq -c should do. Your code also works if you use a for loop, e.g. for f in **/*; do...
– don_crissti
yesterday













@Tim what is the objective of the process, I mean what you would like to achieve by the end, more specifically why you are using cut sort and uniq? The commands seems to be meaningless in providing correct output for cut and sort. If you would please provide example of the desired output this will be very helpful for us to help
– Goro
yesterday





@Tim what is the objective of the process, I mean what you would like to achieve by the end, more specifically why you are using cut sort and uniq? The commands seems to be meaningless in providing correct output for cut and sort. If you would please provide example of the desired output this will be very helpful for us to help
– Goro
yesterday











1 Answer
1






active

oldest

votes

















up vote
2
down vote













You can get find to execute file for each file found.



find . -exec file -b ; |cut -f1|sort|uniq -c


edit



As @Ed-Nevile's comment below removing cut provides more detail for ASCII files.



find . -exec file -b ; |sort|uniq -c





share|improve this answer


















  • 1




    Upvoting as you use -b, but I don't think you should cut the output since several different file types will begin with 'ASCII'.
    – Ed Neville
    yesterday










  • I think -exec file -b + will reduce the number of file processes created.
    – Kamil Maciorowski
    yesterday










  • Certainly will, great update, tks, I wanted to answer his original question as close as possible :-)
    – X Tian
    yesterday










  • 1. Can you please say why exec is preferred here over xargs? and 2. Can you tell me what is wrong syntactically with my attempts using bash string manipulation? I am trying not just to achieve a result, but also to understand why other methods don't work.
    – Tim
    21 hours ago


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













You can get find to execute file for each file found.



find . -exec file -b ; |cut -f1|sort|uniq -c


edit



As @Ed-Nevile's comment below removing cut provides more detail for ASCII files.



find . -exec file -b ; |sort|uniq -c





share|improve this answer


















  • 1




    Upvoting as you use -b, but I don't think you should cut the output since several different file types will begin with 'ASCII'.
    – Ed Neville
    yesterday










  • I think -exec file -b + will reduce the number of file processes created.
    – Kamil Maciorowski
    yesterday










  • Certainly will, great update, tks, I wanted to answer his original question as close as possible :-)
    – X Tian
    yesterday










  • 1. Can you please say why exec is preferred here over xargs? and 2. Can you tell me what is wrong syntactically with my attempts using bash string manipulation? I am trying not just to achieve a result, but also to understand why other methods don't work.
    – Tim
    21 hours ago















up vote
2
down vote













You can get find to execute file for each file found.



find . -exec file -b ; |cut -f1|sort|uniq -c


edit



As @Ed-Nevile's comment below removing cut provides more detail for ASCII files.



find . -exec file -b ; |sort|uniq -c





share|improve this answer


















  • 1




    Upvoting as you use -b, but I don't think you should cut the output since several different file types will begin with 'ASCII'.
    – Ed Neville
    yesterday










  • I think -exec file -b + will reduce the number of file processes created.
    – Kamil Maciorowski
    yesterday










  • Certainly will, great update, tks, I wanted to answer his original question as close as possible :-)
    – X Tian
    yesterday










  • 1. Can you please say why exec is preferred here over xargs? and 2. Can you tell me what is wrong syntactically with my attempts using bash string manipulation? I am trying not just to achieve a result, but also to understand why other methods don't work.
    – Tim
    21 hours ago













up vote
2
down vote










up vote
2
down vote









You can get find to execute file for each file found.



find . -exec file -b ; |cut -f1|sort|uniq -c


edit



As @Ed-Nevile's comment below removing cut provides more detail for ASCII files.



find . -exec file -b ; |sort|uniq -c





share|improve this answer














You can get find to execute file for each file found.



find . -exec file -b ; |cut -f1|sort|uniq -c


edit



As @Ed-Nevile's comment below removing cut provides more detail for ASCII files.



find . -exec file -b ; |sort|uniq -c






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









X Tian

7,41611936




7,41611936







  • 1




    Upvoting as you use -b, but I don't think you should cut the output since several different file types will begin with 'ASCII'.
    – Ed Neville
    yesterday










  • I think -exec file -b + will reduce the number of file processes created.
    – Kamil Maciorowski
    yesterday










  • Certainly will, great update, tks, I wanted to answer his original question as close as possible :-)
    – X Tian
    yesterday










  • 1. Can you please say why exec is preferred here over xargs? and 2. Can you tell me what is wrong syntactically with my attempts using bash string manipulation? I am trying not just to achieve a result, but also to understand why other methods don't work.
    – Tim
    21 hours ago













  • 1




    Upvoting as you use -b, but I don't think you should cut the output since several different file types will begin with 'ASCII'.
    – Ed Neville
    yesterday










  • I think -exec file -b + will reduce the number of file processes created.
    – Kamil Maciorowski
    yesterday










  • Certainly will, great update, tks, I wanted to answer his original question as close as possible :-)
    – X Tian
    yesterday










  • 1. Can you please say why exec is preferred here over xargs? and 2. Can you tell me what is wrong syntactically with my attempts using bash string manipulation? I am trying not just to achieve a result, but also to understand why other methods don't work.
    – Tim
    21 hours ago








1




1




Upvoting as you use -b, but I don't think you should cut the output since several different file types will begin with 'ASCII'.
– Ed Neville
yesterday




Upvoting as you use -b, but I don't think you should cut the output since several different file types will begin with 'ASCII'.
– Ed Neville
yesterday












I think -exec file -b + will reduce the number of file processes created.
– Kamil Maciorowski
yesterday




I think -exec file -b + will reduce the number of file processes created.
– Kamil Maciorowski
yesterday












Certainly will, great update, tks, I wanted to answer his original question as close as possible :-)
– X Tian
yesterday




Certainly will, great update, tks, I wanted to answer his original question as close as possible :-)
– X Tian
yesterday












1. Can you please say why exec is preferred here over xargs? and 2. Can you tell me what is wrong syntactically with my attempts using bash string manipulation? I am trying not just to achieve a result, but also to understand why other methods don't work.
– Tim
21 hours ago





1. Can you please say why exec is preferred here over xargs? and 2. Can you tell me what is wrong syntactically with my attempts using bash string manipulation? I am trying not just to achieve a result, but also to understand why other methods don't work.
– Tim
21 hours ago



Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?