Showing posts with label cut. Show all posts
Showing posts with label cut. Show all posts

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.