LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2019, 02:57 PM   #1
anon033
Member
 
Registered: Mar 2019
Posts: 188

Rep: Reputation: 13
Removing Music/ from Output [Shell Script]


I am writing a simple shell script to print out all of my music in ~/Music. I am wanting to do it using generic shell script (IE no bash specific things). I currently have this
Code:
cd ${HOME} && ls -R Music | sed 's/ //'
which outputs (get ready) all of this: https://privatebin.net/?7f4c76eb503a...0GtX5y21aq/AI=. I want to remove the Music/ that shows before each line and it showing all artist names at the very top of the output (I only need the parts where is shows artist/album/song). I can't figure out how though, can someone point me in the right direction?

I solved the first part, my syntax was wrong when I tried it before. This removed the /Music tid bit:

[code]
cd ${HOME} && ls -R Music | sed 's/ //' | sed 's/Music\///'

[\code]

Last edited by anon033; 05-24-2019 at 03:50 PM.
 
Old 05-24-2019, 03:25 PM   #2
WideOpenSkies
Member
 
Registered: May 2019
Location: /home/
Distribution: Arch Linux
Posts: 166

Rep: Reputation: 61
ls -R lists the files recursively. That's why you're seeing the mp3 files.

If you only want artist folders, you can do:

Code:
ls $HOME/Music
This is assuming you don't have ls aliased to something like ls -la.

Last edited by WideOpenSkies; 05-24-2019 at 03:26 PM.
 
Old 05-24-2019, 03:28 PM   #3
anon033
Member
 
Registered: Mar 2019
Posts: 188

Original Poster
Rep: Reputation: 13
Quote:
Originally Posted by Contrapak View Post
ls -R lists the files recursively. That's why you're seeing the mp3 files.

If you only want artist folders, you can do:

Code:
ls $HOME/Music
This is assuming you don't have ls aliased to something like ls -la.
I mean I want to see output like:

Code:
骨架的/Skeleton:
baby.mp3
cold.mp3
foam.mp3
glowing.mp3
melting.mp3
microwave.mp3
orange.mp3
sewer.mp3
skeleton.mp3
sunset.mp3
but not parts like this
Code:
Music/骨架的:
Holograms
Skeleton
or this

Code:
Music:
2814
メディカル
ニューシティ
チェスマスター
マキシマムザホルモン
3TEETH
サイバー '98
AbductedBy Sharks
Acceptance
Accessto Arasaka
ADOV
AIRJapan
AlienAutopsy
AncientSandtimer
Angelspit
Anti-Flag
AphroditesChild
Archive
Autechre
BlankBanshee
BlindDilemma
BLUNTSIDE
BornOf Osiris
BrokenHKE
BuriedAngel
CarpenterBrut
Celldweller
Chemlab
Chesumasuta
ChuckPerson
COCAINEJESUS
Cold
Combichrist
Cryptex
Cyanotic
Cyberpunkers
DARKPYRAMID
DeadKennedys
deadmau5
DeathGrips
deathsdynamic shroudwmv
Deftones
DisarmoniaMundi
DiskettePark
DistrictUnknown
DJMadson
Download
DrowningPool
ElectricWizard
ELLEGARDEN
Erast
Erra
FatboySlim
FB I __ W A R N I N G
FearFactory
FlyingLotus
ForestSwords
FortRomeau
FutureCity Love Stories
Godhead
GOLDENLIVING ROOM & t e l e p a t h テレパシー能力者
Goldfinger
Grendel
식료품groceries
GumBleed
haircutsfor men
HaloAcid_HKE
Hantasi
Haujobb
Headscan
hedpe
HKE
HKE& t e l e p a t h テレハシー能力者
HOME
HongKong Express
HotWater Music
hyper_devil
hyphyskazerbox
Iconof Coil
Illidiance
InfinityFrequencies
InHearts Wake
Innerpartysystem
Insolence
Invent_Animate
JamesFerraro
JudasPriest
Kamokata
KeitoShimuguchi
KenjiKawai
KillswitchEngage
KingCrimson
KMFDM
LasershipStereo
LassigueBendthaus
Lazerhawk
LeftSpine Down
LimpBizkit
Lorn
LotusFlowers
LuxuryElite
LyndonWier
Machinedrum
MacintoshPlus
マクロスMACROSS82-99
MakeGood Your Escape
Makeupand Vanity Set
Mastodon
Maxeen
MichaelMcCann
Ministry
Mudvayne
MyLife With the Thrill Kill Kult
NaturesSpirit
NeverHeard of It
NewDelhi Express
NewDreams Ltd
NineInch Nails
Nmesh
NOFX
Northlane
Northlane& In Hearts Wake
Novelists
ohGr
OlaFløttum
Orange9mm
Perturbator
Powerman5000
PowerPCME
PrismCorpVirtual Enterprises
PsyborgCorp
RageAgainst the Machine
Rammstein
RayFaded
REEVE
RussianCircles
Samiam
Sandtimer
SAYOHIMEBOU
ShinjukuMad
ShootzyGroove
Shredder1984
ShyChild
SkinnyPuppy
SOiL
SolarFields
Spineshank
Static-X
Stereomud
Steriogram
STΛQQƟVERFLƟ
Subaeris
Suchamazingdoge
Sugarcult
Sybreed
te l e p a t h
te l e p a t h & Agia
te l e p a t h and HKE
te l e p a t h テレパシー能力者
te l e p a t h テレパシー能力者 and 猫 シ Corp
te l e p a t h テレパシー能力者 & Vincent Remember
TelevisionExperience
TELOZKOPE
TheBouncing Souls
TheBrowning
TheClash
THEDARKEST FUTURE
TheEnigma TNG
TheOrb
TheProdigy
TheToy Dolls
TitleFight
Tool
Trivium
TRUSTcompany
UnknownForever
VAPERROR
VariousArtists
VincentRemember
VNVNation
Volumes
waterfrontdining & 猫 シ Corp
WhileShe Sleeps
WhiteTown
Windows96
Windows98の
Wolfsheim
Zackde la Rocha
вовчіособи
Путь
放射性Hi5
░▒▓新しいテラックスライフ▓▒░
暗い自然
死亡渠道
猫シ Corp
脑浊
过失
音LIGHT システム
骨架的
 
Old 05-24-2019, 03:39 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Please post a dozen or so examples of the output of ls with no filtering.
That is, what is the input of the filtering you want to do?
 
1 members found this post helpful.
Old 05-24-2019, 03:46 PM   #5
WideOpenSkies
Member
 
Registered: May 2019
Location: /home/
Distribution: Arch Linux
Posts: 166

Rep: Reputation: 61
You could try working with the tree command in that case.
 
Old 05-24-2019, 04:24 PM   #6
individual
Member
 
Registered: Jul 2018
Posts: 315
Blog Entries: 1

Rep: Reputation: 233Reputation: 233Reputation: 233
Are you using BSD's ls, or GNU's? I'm not familiar with BSD, but what you're looking to do is possible with GNU's ls.
Code:
ls -RF1 Music | grep -v '/$' | tail -n+3 | sed 's!Music/!!'
Here is how it works:
-R means recurse. You seem to have a grasp of that, so I'll move on.
-F means "classify." This option tells ls to append an indicator (*/=>@|) to file name. For directories this appends a single slash '/'.
-1 means print one file per line.

With the trailing slash now appended to directories, grep -v '/$' prints everything but those file names.

tail -n+3 is necessary to remove the initial directory and the blank line left over.
Without tail -n+3:
Code:
Music:

Dir/:
Files
With:
Code:
Dir/:
Files
sed 's!Music/!!' removes 'Music/' from the line.
Type man ls in your terminal to read more options available.

Last edited by individual; 05-24-2019 at 05:25 PM. Reason: I forgot to include the sed portion that removes the leading directory name. Removed unnecessary .*.
 
2 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
special charter at bunch of .csv i want to run script with for loop but not removing in single command it is identifying but not removing dhirendrs Programming 6 09-01-2017 02:38 PM
Wrote Shell in C - piping output from first command to second command, sending to output file issue KarenWest Programming 2 03-31-2016 05:27 PM
[SOLVED] Removing first two lines in the output of shell script laks Programming 3 02-28-2012 09:52 PM
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 12:46 PM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 07:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:42 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
Open Source Consulting | Domain Registration