Thursday, November 30, 2006

UNIX: Simple one-liner to chop last field from file

So, I wanted to chop off the last field in a file extension (bob.joy.txt, for example).
Here's is a simple solution, using reverse (rev), ls, cut and a for loop:

for i in `ls *.txt`; do mv $i `echo $i|rev |cut -d '.' -f2-|rev`;done

There's prob a cleaner way, but this was quick and easy.

2 comments:

Anonymous said...

Hey Wrex,

I thought I would say "Hi". This is the second time I have found your blog while Googling for VCS or VxVM info. I don't know if you remember me or not (it's been a LONG time). My name is Edward Cox. You taught my Sun Sys. Admin. and TCP/IP class. Anyway, I now work for Symantec. I am HA Certified in 3.5 (so it has expired) but since I was hired last August I have been on a long term NetBackup upgrade project.

Do you still work at the same place?

If you still have my e-mail address you can e-mail me... (or don't) (as you would say).

Sounds like we've got a few things in common. Cycles, Sun, Veritas and our dislike of Windows & Bush.

Edward

Wrex's World said...

Doood!

Yea, I remember ya! How are you? I'm glad to see you landed there. :-)

Send me another message with your email addy and I'll respond. I won't publish it, here.

Good to hear from you. :-)

Wrex