Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211

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
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,046

Rep: Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592Reputation: 2592
Just thought I would throw in 2 cents
items=(${video//[_.]/ })
(( total += ${items[-2]} ))
Also, do not use ls to feed a for loop, you can simply use a straight glob:
for video in *
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
Senior Member
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

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

Some reference tables

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


Would give you

'nothing' after the second slash, so in effect 'deletes' the pattern

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

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.


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 01:48 AM.

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