[LUAU] not using SED to extract song, artist, and album from my iTunes Music List Export
Jim Thompson
jim at netgate.com
Thu Sep 28 05:12:37 PDT 2006
On Sep 28, 2006, at 12:15 AM, R. Scott Belford wrote:
> Jim Thompson wrote:
>
>> Oops, Vince is right.
>
> Okay, so I paste this into my terminal window
>
> cat Music.txt | awk '{FS="\t";RS="\r";printf("\"%s\" %s %s\n", $1,
> $2, $4)}' < /tmp/scott > /tmp/scott.out
>
> and I get this on my osx machine
>
> awk: i/o error occurred on /dev/stdin
> source line number 1
>
> and this on my debian box
>
> awk: cmd. line:1: fatal: file `-' is a directory
>
> I know it is me, but I don't know what to do.
You're doing something really strange.
First, you've re-directed stdin ("< /tmp/scott") **AND** you're
trying to feed stdin via a pipeline ("cat Music.txt" | ").
Next, your script is horked for reasons I won't go into. In order to
set FS (and RS, if its needed) without using '-F' (and there is no
switch for RS), you have to do something like:
#!/bin/awk -f
BEGIN {
# change the record separator from newline to nothing
RS=""
# change the field separator from whitespace to newline
FS="\n"
}
{
# print the second and third line of the file
print $2, $3;
}
Note the "BEGIN" section, and what it does, and then the
"body" (second set of curly braces) which does the actual "work".
Try this:
awk -F"\t"'{printf("name:\"%s\" artist:\"%s\" album:\"%s\"\n", $1,
$2, $4)}' < /tmp/scott > /tmp/scott.out
it works... on my OS X box. The same script works on a Debian linux
box too. And... it works on hosef.org, as shown.
In fact, if you want, look for the line above in a file named "/tmp/
doit4scott", and the input/output files as indicated (also in /tmp).
The equivalent 'script' would look like:
#!/bin/awk -f
BEGIN {
# change the field separator from whitespace to TAB
FS="\t"
}
{
#
# print the quoted contents of the first, second and fourth columns
in the file, with labels.
#
printf("name:\"%s\" artist:\"%s\" album:\"%s\"\n", $1, $2, $4)
}
More information about the LUAU
mailing list