PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > How to parse spaces when cat'ing a file?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

How to parse spaces when cat'ing a file?

Réponse
 
LinkBack Outils de la discussion
Vieux 21/03/2008, 04h18   #1
somebody
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to parse spaces when cat'ing a file?

Given this file called playlist.txt:

"/music/Country/Rascal Flatts/Rascal Flatts/It's Not Just Me.mp3"
"/music/Rock/AC-DC/Back In Black/AC-DC - 09 - Shake A Leg.mp3"

If I cat the file in a meta command, it breaks up each line on the spaces
(See below) How can I ensure the entire line is passed to an application
like mplayer?


for i in $(cat playlist.txt); do echo "$i"; done
"/music/Country/Rascal
Flatts/Rascal
Flatts/It's
Not
Just
Me.mp3"
"/music/Rock/AC-DC/Back
In
Black/AC-DC
-
09
-
Shake
A
Leg.mp3"
  Réponse avec citation
Vieux 21/03/2008, 04h50   #2
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to parse spaces when cat'ing a file?



On 3/20/2008 10:18 PM, somebody wrote:
> Given this file called playlist.txt:
>
> "/music/Country/Rascal Flatts/Rascal Flatts/It's Not Just Me.mp3"
> "/music/Rock/AC-DC/Back In Black/AC-DC - 09 - Shake A Leg.mp3"
>
> If I cat the file in a meta command, it breaks up each line on the spaces
> (See below) How can I ensure the entire line is passed to an application
> like mplayer?
>
>
> for i in $(cat playlist.txt); do echo "$i"; done
> "/music/Country/Rascal
> Flatts/Rascal
> Flatts/It's
> Not
> Just
> Me.mp3"
> "/music/Rock/AC-DC/Back
> In
> Black/AC-DC
> -
> 09
> -
> Shake
> A
> Leg.mp3"


Try this:

while IFS= read -r i
do
printf "%s\n" "$i"
done < playlist.txt

Ed.

  Réponse avec citation
Vieux 21/03/2008, 11h36   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to parse spaces when cat'ing a file?

2008-03-20, 23:18(-04), somebody:
> Given this file called playlist.txt:
>
> "/music/Country/Rascal Flatts/Rascal Flatts/It's Not Just Me.mp3"
> "/music/Rock/AC-DC/Back In Black/AC-DC - 09 - Shake A Leg.mp3"
>
> If I cat the file in a meta command, it breaks up each line on the spaces
> (See below) How can I ensure the entire line is passed to an application
> like mplayer?

[...]

That file happens to be in a format recognised by xargs, so
that's only:

xargs echo < playlist.txt

See man xargs for more options.

--
Stéphane
  Réponse avec citation
Vieux 21/03/2008, 11h50   #4
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to parse spaces when cat'ing a file?

On 2008-03-21, Stephane CHAZELAS <this.address@is.invalid> wrote:
>
>
> 2008-03-20, 23:18(-04), somebody:
>> Given this file called playlist.txt:
>>
>> "/music/Country/Rascal Flatts/Rascal Flatts/It's Not Just Me.mp3"
>> "/music/Rock/AC-DC/Back In Black/AC-DC - 09 - Shake A Leg.mp3"
>>
>> If I cat the file in a meta command, it breaks up each line on the spaces
>> (See below) How can I ensure the entire line is passed to an application
>> like mplayer?

> [...]
>
> That file happens to be in a format recognised by xargs, so
> that's only:
>
> xargs echo < playlist.txt
>

See man mplayer. You can use a playlist file on the command line.
(Not sure if it requires a special file format, but that's easy to find
out.)
  Réponse avec citation
Vieux 23/03/2008, 03h52   #5
Conrad J. Sabatier
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to parse spaces when cat'ing a file?

On Thu, 20 Mar 2008 23:18:26 -0400, somebody wrote:

> Given this file called playlist.txt:
>
> "/music/Country/Rascal Flatts/Rascal Flatts/It's Not Just Me.mp3"
> "/music/Rock/AC-DC/Back In Black/AC-DC - 09 - Shake A Leg.mp3"
>
> If I cat the file in a meta command, it breaks up each line on the
> spaces (See below) How can I ensure the entire line is passed to an
> application like mplayer?
>
>
> for i in $(cat playlist.txt); do echo "$i"; done "/music/Country/Rascal
> Flatts/Rascal
> Flatts/It's
> Not
> Just
> Me.mp3"
> "/music/Rock/AC-DC/Back
> In
> Black/AC-DC
> -
> 09
> -
> Shake
> A
> Leg.mp3"


You don't specify which shell you're using, but in bash, it's possible to
specify a "read" command without any variable, in which case the entire
line is read and stored in the default $REPLY variable.

For example:

while read
do
mplayer "$REPLY"
done < playlist.txt

Caveat: anytime you find yourself using "cat", try thinking again about
an alternative way to accomplish what you're trying to do. UUOC (Useless
Use Of Cat) awards abound in Usenet.

--
Conrad J. Sabatier <conrads@cox.net>

"Procrastinate now; don't put it off." -- Ellen Degeneres
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h29.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12342 seconds with 13 queries