Skip to contentSkip to conversation

FSpecs

DISCUSSION BEN RITCHEY 5 participants 6 messages Nov 14, 2002 – Nov 15, 2002 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Originally to: ALL

Would it be possible in a Bash script to munge a Long File Name to the older DOS 8.3 format?

In my case I need the first 8 characters and the last 4 (.xxx) ... the resulting string would then be used as an argument for another command. :)

--
Keep the faith,

: Ben http://bellsouthpwp.net/c/m/cmech617 ICQ #32457590
:
+ WildCat! Board 24/7 (337) 232-4155 33.6kBps 8,N,1 Files!

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#1 lore raw

It would be a lot easier to do it with gawk or perl. -----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of BEN RITCHEY
Sent: Thursday, November 14, 2002 3:57 AM
To: [email protected]
Subject: FSpecs

Originally to: ALL

Would it be possible in a Bash script to munge a Long File Name to the older DOS 8.3 format?

In my case I need the first 8 characters and the last 4 (.xxx) ... the resulting string would then be used as an argument for another command. :)

--
Keep the faith,

: Ben http://bellsouthpwp.net/c/m/cmech617 ICQ #32457590
:
+ WildCat! Board 24/7 (337) 232-4155 33.6kBps 8,N,1 Files!

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#2 lore raw
In reply to BEN RITCHEY

Use cut and/or gawk

----- Original Message -----
From: "BEN RITCHEY" <[email protected]>
To: <[email protected]>
Sent: Thursday, November 14, 2002 2:56 AM
Subject: FSpecs

Quoted 3 lines

Originally to: ALL

Would it be possible in a Bash script to munge a Long File Name to the

older

Quoted 12 lines

DOS 8.3 format?

In my case I need the first 8 characters and the last 4 (.xxx) ... the resulting string would then be used as an argument for another command. :)

--
Keep the faith,

: Ben http://bellsouthpwp.net/c/m/cmech617 ICQ #32457590
:
+ WildCat! Board 24/7 (337) 232-4155 33.6kBps 8,N,1 Files!

Quoted 5 lines

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#3 lore raw
In reply to BEN RITCHEY
Quoted 5 lines · BEN RITCHEY

Would it be possible in a Bash script to munge a
Long File Name to the older DOS 8.3 format?
In my case I need the first 8 characters and the
last 4 (.xxx)

To which Paul Kraus replied:

Quoted 1 line

It would be a lot easier to do it with gawk or perl.

Quoted 1 line · And hackob

Use cut and/or gawk

Actually guys, all you need is bash:
--------------------------------------------------
example="long-filename.to.munge.txt"
echo ${example%${example#????????}}.${example##*.}
--------------------------------------------------

Cheers,
Steven

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

#4 lore raw

All the approaches suggested for this exercise assume that one need not worry about generating a UNIQUE 8.3 filename from the long filename. Is that assumption appropriate to Ben's real, underlying problem? Or does it risk overwriting a file with a later one (e.g., shortnam-abcd.txt and shortnam-efgh.txt both become shortnam.txt)?

Quoted 10 lines · At 02:43 PM 11/15/02 +0000, [email protected] wrote:
Quoted 5 lines · BEN RITCHEY

Would it be possible in a Bash script to munge a
Long File Name to the older DOS 8.3 format?
In my case I need the first 8 characters and the
last 4 (.xxx)

To which Paul Kraus replied:

Quoted 1 line

It would be a lot easier to do it with gawk or perl.

Quoted 8 lines
Quoted 1 line · And hackob

Use cut and/or gawk

Actually guys, all you need is bash:
--------------------------------------------------
example="long-filename.to.munge.txt"
echo ${example%${example#????????}}.${example##*.}
--------------------------------------------------

--
-------------------------------------------"Never tell me the odds!"--------
Ray Olszewski -- Han Solo
Palo Alto, California, USA [email protected]
-------------------------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 9 lines · Ray Olszewski
Quoted 8 lines
Quoted 3 lines

In my case I need the first 8 characters and the
last 4 (.xxx)

--------------------------------------------------
example="long-filename.to.munge.txt"
echo ${example%${example#????????}}.${example##*.}
--------------------------------------------------

Quoted 5 lines

All the approaches suggested for this exercise assume that one need not worry about generating a UNIQUE 8.3 filename from the long filename. Is that assumption appropriate to Ben's real, underlying problem? Or does it risk overwriting a file with a later one

OK, Ray, here's one off the top of my head. I'm sure it can be improved, but it will do for a start.
-------------------------------------------------------------
#!/bin/bash
from="/home/ichi" to="/tmp"
for i in ls $from ; do
front=${i%.*} ; back=""
echo $i | grep "\." >/dev/null ; [ $? = 0 ] && back=.${i##*.} [ ${#front} -gt 8 ] && front=${front%${front#????????}} [ ${#back} -gt 4 ] && back=${back%${back#????}} front=echo $front | tr " ." "__"
new=$front$back
for j in ls $to ; do
case $j in $new)
echo "$new already exists. Input new name." read new
esac
done
echo $new ### YOUR OUTPUT ROUTINE GOES HERE ### done
--------------------------------------------------------------

I suppose somebody is going to tell that there is a built-in command that does this automatically. Ah, well.

Cheers,
Steven

-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs