LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
 
Search this Thread
Old 02-25-2014, 06:07 PM   #16
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,431
Blog Entries: 1

Rep: Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144

The bash functionality is as fast as you are going to get. Anything you add to it will just delay the process and be another abstraction or layer.
 
1 members found this post helpful.
Old 02-26-2014, 12:44 AM   #17
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,899

Rep: Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096Reputation: 2096
Just thought I would throw in 2 cents
Code:
video=2014_02_24-10_30_14_525__15000.mp4
items=(${video//[_.]/ })
(( total += ${items[-2]} ))
Also, do not use ls to feed a for loop, you can simply use a straight glob:
Code:
for video in *
do
...
done
Later you will learn about the dangers of word splitting which the ls version is subject to but the glob is not.
In your particular case it currently may not be an issue as none of the files contain whitespace, but better to get in a good habit now so as not to get caught out later

I recommend read this site all the way through when you have time as it helps with many pitfalls
 
1 members found this post helpful.
Old 02-26-2014, 05:32 AM   #18
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Tldp chapter on string manipulation

http://tldp.org/LDP/abs/html/string-manipulation.html

Some reference tables
http://tldp.org/LDP/abs/html/refcards.html


Actually, technically the use of # might be a better fit,
/ is replacement, but since 'nothing' after it replace with nothing

Sorry, didn't explain that very well

${video/*__/foo_}

Would give you
foo_15000.mp4

${video/*__/}
'nothing' after the second slash, so in effect 'deletes' the pattern

${video#*__}
Same result, less typing




The awk deserves a quick explination


The -F , is defining the feild separator(s)

[_.] is 'special' in essence it means

_ or .

Now for the print part

NF is a special internal variable to awk,
For each new record (usually each line by default ) it counts the Number of Fields, and sets NF to that value

For fun, replace the $(NF-1) with NF, you should get a number
now do

Code:
NF" "$NF" "(NF-1)" "$(NF-1)" "(NF-2)" "$(NF-2)
that should give you an idea of what is going on
 
1 members found this post helpful.
  


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
[SOLVED] Combining With awk If Possible: ali2011 Programming 1 01-14-2012 04:38 PM
[SOLVED] Combining Two Files Using AWK ali2011 Programming 8 12-15-2011 10:03 PM
AWK - combining multiple columns AlexYZ Programming 5 02-24-2010 07:09 AM
Combining two commands into one spes_hominis Linux - Software 5 05-16-2007 10:51 AM


All times are GMT -5. The time now is 10:27 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration