Home
Man
Search
Today's Posts
Register

All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Super Simple Script to remove first characters of any png file

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 03-04-2013
Super Simple Script to remove first characters of any png file

Well I searched the net with varying success, but it seems kinda hard to find a one/max 2 lined command to:

strip all *.png files in the folder from their first two characters.

Any help is appreciated.


In DOS commandline of course...
# 2  
Old 03-04-2013
Strip the first 2 bytes from every png file, do you mean?

If you can use busybox win32, I'd try this in a busybox shell:

Code:
for FILE in *.png ; do ( dd bs=2 count=1 > JUNK ; cat ) < $FILE > new-$FILE ; echo mv new-$FILE $FILE ; done
rm -f JUNK

Remove the echo from that once you've tested it and are sure it does what you want.

And it'd make much more sense to look at if you didn't insist on jamming it into 2 lines.
The Following User Says Thank You to Corona688 For This Useful Post:
rbatte1 (03-05-2013)
# 3  
Old 03-05-2013
Are you talking of file names or file contents to strip?
# 4  
Old 03-05-2013
Just the filenames.
# 5  
Old 03-05-2013
With a ksh variable, you could do the following:-
Code:
#!/bin/ksh

for file in `ls *.png`
do
   echo mv $file "${file#??}"
done

Is this what you're after, or have I missed the point?

This will output the commands so you can check.


I hope that this helps,
Robin
Liverpool/Blackburn
UK
# 6  
Old 03-05-2013
Quote:
Originally Posted by pasc
Just the filenames.
Oh.

Well that's simpler, I guess.

More code for busybox bash:

Code:
for X in *.png ; do echo mv "$X" "${X:2}" ; done

Remove the 'echo' once you've tested and are sure it does what you want.
# 7  
Old 03-05-2013
Quote:
Originally Posted by rbatte1
With a ksh variable, you could do the following:-
[CODE]#!/bin/ksh

for file in `ls *.png`
That is a rare and interesting combination useless use of backticks and useless use of ls *. The shell does not need the help of ls or backticks to use *.

I doubt the OP has KSH, but busybox for windows has sh as noted.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remove characters from the file expert Shell Programming and Scripting 9 05-08-2013 02:06 PM
Want to remove the last characters from each row of csv using shell script rajak.net Shell Programming and Scripting 24 12-15-2011 05:54 AM
Remove the characters from the file Kattoor Shell Programming and Scripting 6 02-16-2010 01:48 AM
How to remove Ctlr-M characters from file from a unix script akashtcs Shell Programming and Scripting 2 08-18-2009 05:11 AM
How to remove ^M characters from a zip file? bhaskar_m Shell Programming and Scripting 2 06-25-2009 08:01 AM
sed script to remove nth characters from end of filename Monkey Dean Shell Programming and Scripting 2 06-24-2009 02:39 AM
Remove characters from file name mrlayance Shell Programming and Scripting 5 04-28-2009 09:04 PM
SUPER simple bash script to repeat a command... robfindlay Shell Programming and Scripting 6 03-23-2009 05:12 PM
sed to remove last 2 characters of txt file ajp7701 Shell Programming and Scripting 1 10-29-2008 08:23 PM
Script to find and remove characters Zerby Shell Programming and Scripting 5 01-30-2008 02:16 AM


All times are GMT -4. The time now is 02:12 PM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password