xargs plus shell string manipulation vs sed [duplicate]
Clash 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.
shell sed xargs
marked as duplicate by don_crissti, Goro, Jeff Schaller, Kusalananda
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.
 |Â
show 1 more comment
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.
shell sed xargs
marked as duplicate by don_crissti, Goro, Jeff Schaller, Kusalananda
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 thefile
command is taking too long, I'd revert to extension-based type.
â Tim
yesterday
... if you want the mime types thenfind . -type f -exec file --brief --mime-type ; | sort | uniq -c
should do. Your code also works if you use afor
loop, e.g. forf 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 usingcut
sort
anduniq
? 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
 |Â
show 1 more comment
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.
shell sed xargs
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
shell sed xargs
edited 50 mins ago
asked yesterday
Tim
1535
1535
marked as duplicate by don_crissti, Goro, Jeff Schaller, Kusalananda
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
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 thefile
command is taking too long, I'd revert to extension-based type.
â Tim
yesterday
... if you want the mime types thenfind . -type f -exec file --brief --mime-type ; | sort | uniq -c
should do. Your code also works if you use afor
loop, e.g. forf 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 usingcut
sort
anduniq
? 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
 |Â
show 1 more comment
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 thefile
command is taking too long, I'd revert to extension-based type.
â Tim
yesterday
... if you want the mime types thenfind . -type f -exec file --brief --mime-type ; | sort | uniq -c
should do. Your code also works if you use afor
loop, e.g. forf 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 usingcut
sort
anduniq
? 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
 |Â
show 1 more comment
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
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 offile
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 whyexec
is preferred here overxargs
? 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
add a comment |Â
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
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 offile
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 whyexec
is preferred here overxargs
? 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
add a comment |Â
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
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 offile
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 whyexec
is preferred here overxargs
? 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
add a comment |Â
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
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
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 offile
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 whyexec
is preferred here overxargs
? 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
add a comment |Â
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 offile
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 whyexec
is preferred here overxargs
? 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
add a comment |Â
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 afor
loop, e.g. forf 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
anduniq
? 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