Pass arguments from file line by line to function
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
4
down vote
favorite
I have list of some mp3's:
song 1.mp3
song 2.mp3
.
.
.
song 349.mp3
I can see their bitrate via right mouse button -> Properties -> Audio/Video,
but also I can check it using the terminal command
file "song 1.mp3"
I'd like to find out which bitrate from my list is most frequently used, so I thought it would be nicely done via shell i.e. shell script.
I would lose too much time if I typed
file "song 1.mp3"; file "song 2.mp3"; ... ; file "song 349.mp3"
So, my question is :
Can we pass arguments line by line from some text file to shell function?
An additional problem is that my song names contain spaces.
command-line bash scripts
add a comment |Â
up vote
4
down vote
favorite
I have list of some mp3's:
song 1.mp3
song 2.mp3
.
.
.
song 349.mp3
I can see their bitrate via right mouse button -> Properties -> Audio/Video,
but also I can check it using the terminal command
file "song 1.mp3"
I'd like to find out which bitrate from my list is most frequently used, so I thought it would be nicely done via shell i.e. shell script.
I would lose too much time if I typed
file "song 1.mp3"; file "song 2.mp3"; ... ; file "song 349.mp3"
So, my question is :
Can we pass arguments line by line from some text file to shell function?
An additional problem is that my song names contain spaces.
command-line bash scripts
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have list of some mp3's:
song 1.mp3
song 2.mp3
.
.
.
song 349.mp3
I can see their bitrate via right mouse button -> Properties -> Audio/Video,
but also I can check it using the terminal command
file "song 1.mp3"
I'd like to find out which bitrate from my list is most frequently used, so I thought it would be nicely done via shell i.e. shell script.
I would lose too much time if I typed
file "song 1.mp3"; file "song 2.mp3"; ... ; file "song 349.mp3"
So, my question is :
Can we pass arguments line by line from some text file to shell function?
An additional problem is that my song names contain spaces.
command-line bash scripts
I have list of some mp3's:
song 1.mp3
song 2.mp3
.
.
.
song 349.mp3
I can see their bitrate via right mouse button -> Properties -> Audio/Video,
but also I can check it using the terminal command
file "song 1.mp3"
I'd like to find out which bitrate from my list is most frequently used, so I thought it would be nicely done via shell i.e. shell script.
I would lose too much time if I typed
file "song 1.mp3"; file "song 2.mp3"; ... ; file "song 349.mp3"
So, my question is :
Can we pass arguments line by line from some text file to shell function?
An additional problem is that my song names contain spaces.
command-line bash scripts
command-line bash scripts
edited Apr 1 at 0:17
![](https://i.stack.imgur.com/eVuAv.png?s=32&g=1)
![](https://i.stack.imgur.com/eVuAv.png?s=32&g=1)
wjandrea
7,18342255
7,18342255
asked Mar 31 at 23:31
mk1024
134211
134211
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
9
down vote
Assuming your list of files is one filename per line, the xargs
utility should be able to handle filenames with spaces in them if you specify newline as the delimiting character e.g.
xargs -d 'n' file < filelist.txt
If you prefer to use a shell function
while IFS= read -r f; do [[ -z "$f" ]] || file "$f"; done < filelist.txt
add a comment |Â
up vote
5
down vote
You can use a shell glob like *.mp3
to select all files in the current directory that end with .mp3
. This will automagically take care of spaces and other special characters as well.
On an mp3 I tested, I got output like this for file
:
01 - Mystery Of A Blood Red Rose.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 56 kbps, 44.1 kHz, Stereo
You said you are interested in the bit rate, i.e. 56 kbps
here. We can use grep
to extract only that part of the output with a regular expression like 'd+s+kbps'
(one or more digits, followed by one or more spaces, followed by the string "kbps").
So far, you can use this to show only the bit rate information for all mp3 files in the current directory:
file *.mp3 | grep -Po 'd+s+kbps'
Now this produces a long list with one line per file, but you wanted a nice statistic with total counts. We can do that by sorting the list first (using natural number sort mode) and then counting how often each unique line appears. The tools for this are sort
and uniq
:
file *.mp3 | grep -Po 'd+s+kbps' | sort -n | uniq -c
On one of my music folders, the output looked like below. First number is the file count, second the bit rate:
16 32 kbps
18 56 kbps
67 128 kbps
3 192 kbps
6 256 kbps
38 320 kbps
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
Assuming your list of files is one filename per line, the xargs
utility should be able to handle filenames with spaces in them if you specify newline as the delimiting character e.g.
xargs -d 'n' file < filelist.txt
If you prefer to use a shell function
while IFS= read -r f; do [[ -z "$f" ]] || file "$f"; done < filelist.txt
add a comment |Â
up vote
9
down vote
Assuming your list of files is one filename per line, the xargs
utility should be able to handle filenames with spaces in them if you specify newline as the delimiting character e.g.
xargs -d 'n' file < filelist.txt
If you prefer to use a shell function
while IFS= read -r f; do [[ -z "$f" ]] || file "$f"; done < filelist.txt
add a comment |Â
up vote
9
down vote
up vote
9
down vote
Assuming your list of files is one filename per line, the xargs
utility should be able to handle filenames with spaces in them if you specify newline as the delimiting character e.g.
xargs -d 'n' file < filelist.txt
If you prefer to use a shell function
while IFS= read -r f; do [[ -z "$f" ]] || file "$f"; done < filelist.txt
Assuming your list of files is one filename per line, the xargs
utility should be able to handle filenames with spaces in them if you specify newline as the delimiting character e.g.
xargs -d 'n' file < filelist.txt
If you prefer to use a shell function
while IFS= read -r f; do [[ -z "$f" ]] || file "$f"; done < filelist.txt
answered Mar 31 at 23:54
steeldriver
63k1198166
63k1198166
add a comment |Â
add a comment |Â
up vote
5
down vote
You can use a shell glob like *.mp3
to select all files in the current directory that end with .mp3
. This will automagically take care of spaces and other special characters as well.
On an mp3 I tested, I got output like this for file
:
01 - Mystery Of A Blood Red Rose.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 56 kbps, 44.1 kHz, Stereo
You said you are interested in the bit rate, i.e. 56 kbps
here. We can use grep
to extract only that part of the output with a regular expression like 'd+s+kbps'
(one or more digits, followed by one or more spaces, followed by the string "kbps").
So far, you can use this to show only the bit rate information for all mp3 files in the current directory:
file *.mp3 | grep -Po 'd+s+kbps'
Now this produces a long list with one line per file, but you wanted a nice statistic with total counts. We can do that by sorting the list first (using natural number sort mode) and then counting how often each unique line appears. The tools for this are sort
and uniq
:
file *.mp3 | grep -Po 'd+s+kbps' | sort -n | uniq -c
On one of my music folders, the output looked like below. First number is the file count, second the bit rate:
16 32 kbps
18 56 kbps
67 128 kbps
3 192 kbps
6 256 kbps
38 320 kbps
add a comment |Â
up vote
5
down vote
You can use a shell glob like *.mp3
to select all files in the current directory that end with .mp3
. This will automagically take care of spaces and other special characters as well.
On an mp3 I tested, I got output like this for file
:
01 - Mystery Of A Blood Red Rose.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 56 kbps, 44.1 kHz, Stereo
You said you are interested in the bit rate, i.e. 56 kbps
here. We can use grep
to extract only that part of the output with a regular expression like 'd+s+kbps'
(one or more digits, followed by one or more spaces, followed by the string "kbps").
So far, you can use this to show only the bit rate information for all mp3 files in the current directory:
file *.mp3 | grep -Po 'd+s+kbps'
Now this produces a long list with one line per file, but you wanted a nice statistic with total counts. We can do that by sorting the list first (using natural number sort mode) and then counting how often each unique line appears. The tools for this are sort
and uniq
:
file *.mp3 | grep -Po 'd+s+kbps' | sort -n | uniq -c
On one of my music folders, the output looked like below. First number is the file count, second the bit rate:
16 32 kbps
18 56 kbps
67 128 kbps
3 192 kbps
6 256 kbps
38 320 kbps
add a comment |Â
up vote
5
down vote
up vote
5
down vote
You can use a shell glob like *.mp3
to select all files in the current directory that end with .mp3
. This will automagically take care of spaces and other special characters as well.
On an mp3 I tested, I got output like this for file
:
01 - Mystery Of A Blood Red Rose.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 56 kbps, 44.1 kHz, Stereo
You said you are interested in the bit rate, i.e. 56 kbps
here. We can use grep
to extract only that part of the output with a regular expression like 'd+s+kbps'
(one or more digits, followed by one or more spaces, followed by the string "kbps").
So far, you can use this to show only the bit rate information for all mp3 files in the current directory:
file *.mp3 | grep -Po 'd+s+kbps'
Now this produces a long list with one line per file, but you wanted a nice statistic with total counts. We can do that by sorting the list first (using natural number sort mode) and then counting how often each unique line appears. The tools for this are sort
and uniq
:
file *.mp3 | grep -Po 'd+s+kbps' | sort -n | uniq -c
On one of my music folders, the output looked like below. First number is the file count, second the bit rate:
16 32 kbps
18 56 kbps
67 128 kbps
3 192 kbps
6 256 kbps
38 320 kbps
You can use a shell glob like *.mp3
to select all files in the current directory that end with .mp3
. This will automagically take care of spaces and other special characters as well.
On an mp3 I tested, I got output like this for file
:
01 - Mystery Of A Blood Red Rose.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 56 kbps, 44.1 kHz, Stereo
You said you are interested in the bit rate, i.e. 56 kbps
here. We can use grep
to extract only that part of the output with a regular expression like 'd+s+kbps'
(one or more digits, followed by one or more spaces, followed by the string "kbps").
So far, you can use this to show only the bit rate information for all mp3 files in the current directory:
file *.mp3 | grep -Po 'd+s+kbps'
Now this produces a long list with one line per file, but you wanted a nice statistic with total counts. We can do that by sorting the list first (using natural number sort mode) and then counting how often each unique line appears. The tools for this are sort
and uniq
:
file *.mp3 | grep -Po 'd+s+kbps' | sort -n | uniq -c
On one of my music folders, the output looked like below. First number is the file count, second the bit rate:
16 32 kbps
18 56 kbps
67 128 kbps
3 192 kbps
6 256 kbps
38 320 kbps
answered Apr 1 at 0:02
![](https://i.stack.imgur.com/m8DYH.jpg?s=32&g=1)
![](https://i.stack.imgur.com/m8DYH.jpg?s=32&g=1)
Byte Commander
59.4k26159267
59.4k26159267
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1020947%2fpass-arguments-from-file-line-by-line-to-function%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password