LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-19-2019, 12:47 PM   #1
redpenguin2
LQ Newbie
 
Registered: Dec 2009
Posts: 8

Rep: Reputation: 0
Copy .TS files but not .2.TS files?


I have a former Mythbuntu/Ubuntu system running MythTV.

My MythTV outputs .ts files and I have a script called Mythlink.pl.

MythTV just outputs weird names like 7006_2343644.ts so the script makes a folder of sym links named like "ShowName-Title-RecordDate.ts".

The problem is, for many files lately it has been creating two sym links.

A.ts & A.2.ts.

Because they are sym links, I have to use the cp command to copy them to another location.

My problem is, how can I easily tell cp, I only want .ts not .2.ts? I know I can't just use ShowName*.ts as that picks up the .2.ts files also, then I have to delete all the extra afterwards.
 
Old 07-19-2019, 12:51 PM   #2
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Does find let you specify the end of a line? Then pipe it to cp?
 
Old 07-19-2019, 12:56 PM   #3
redpenguin2
LQ Newbie
 
Registered: Dec 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by 273 View Post
Does find let you specify the end of a line? Then pipe it to cp?
Yes, but I am not quite sure what to feed to find as something like *.ts just gives the .2.ts files also.
 
Old 07-19-2019, 01:19 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Two thoughts:
Delete the extras before you copy:
Code:
rm *2.ts
-- that would also work afterwards.

Address the glitch in Mythlink.pl that's creating the 2.ts files in the first place.
 
Old 07-19-2019, 01:26 PM   #5
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by redpenguin2 View Post
Yes, but I am not quite sure what to feed to find as something like *.ts just gives the .2.ts files also.
i am suggesting you man find and look for a way to specify end of line.
 
Old 07-19-2019, 01:29 PM   #6
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Hmm, perhaps it's not that simple:
https://unix.stackexchange.com/quest...-line-with-sed
 
Old 07-19-2019, 01:42 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
give this a go.
Code:
#!/bin/bash

while read f
do
	g=${f//./ }
	[[ ! "$g" =~ '2' ]] && echo $g
done < <(find $1 -type f -iname "*.ts")
removes the . (period), hunts for the 2, if not 2 within string, then act on it, or
Code:
#!/bin/bash

while read f
do
	g=${f//./ }
	[[ ! "$g" =~ '2' ]] && { echo "$f" ; } || { rm "$f" ; } 
done < <(find $1 -type f -iname "*.ts")

###################

#!/bin/bash
copy2=/someWhereElse
while read f
do
	g=${f//./ }
    if	[[ "$g" =~ '2' ]] ; then
          rm "$f"
     else 
         cp "$f" "$copy2"
    fi
done < <(find $1 -type f -iname "*.ts")

Last edited by BW-userx; 07-19-2019 at 01:51 PM.
 
1 members found this post helpful.
Old 07-19-2019, 02:12 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Code:
[[ "$g" =~ '2' ]]

[[ ! "$g" =~ '2' ]]
Too cool! Looks just like perl...did not know that would work in bash!
 
Old 07-19-2019, 02:45 PM   #9
redpenguin2
LQ Newbie
 
Registered: Dec 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Wow thanks folks for all your replies!

I will have to study the examples further.

I know basic wildcards but have been having trouble trying to learn RegEx.

I have done text replacement with sed, tr, gawk, etc so I know the general concept just have to get the regex patterns down.
 
Old 07-19-2019, 02:58 PM   #10
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,001

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
Some of the members at LQ are awesome with this stuff as you can see.
 
Old 07-19-2019, 03:08 PM   #11
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
The regex BW-userx has suggested are testing for the presence (or absence) of a 2 in the file name.
One can use globbing to test for presence:
Code:
*2.ts
or just
*2*
but I'm not thinking of a way to use globs to test for the absence of a 2.

Don't confuse the two. Shell globbing is not regex. Different syntax and capability entirely. Some of the same symbols, tho, just to be confusing.
Your original question is about globbing. (which is not to say that a regex solution is in any way wrong...I certainly liked what BW-userx posted!)
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy installation from one HDD to another, which directory NOT to copy? bfzhou Linux - Newbie 9 03-16-2016 11:59 AM
cp how to copy hidden files and copy recusively without over writing ballsystemlord Linux - Software 5 05-25-2015 02:08 PM
Want to change how pasted files are named "(copy)," "(another copy)," "(3rd copy)" L a r r y Linux - Desktop 3 08-24-2013 03:39 PM
[bash] Copy files, move files but not added ones errgrdgds Programming 4 05-24-2013 06:46 AM
LXer: Sun's 'Project Copy Linux' not a Linux copy LXer Syndicated Linux News 0 07-29-2007 08:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:57 AM.

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
Open Source Consulting | Domain Registration