Unix/Linux Go Back    


Windows & DOS: Issues & Discussions 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

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-04-2013   -   Original Discussion by pasc
pasc's Unix or Linux Image
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 7 January 2018, 4:54 PM EST
Posts: 141
Thanks: 26
Thanked 1 Time in 1 Post
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...
Sponsored Links
    #2  
Old Unix and Linux 03-04-2013   -   Original Discussion by pasc
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 May 2018, 3:04 PM EDT
Location: Saskatchewan
Posts: 22,680
Thanks: 1,179
Thanked 4,324 Times in 3,987 Posts
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)
Sponsored Links
    #3  
Old Unix and Linux 03-05-2013   -   Original Discussion by pasc
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 26 May 2018, 5:24 PM EDT
Location: Aachen, Germany
Posts: 12,756
Thanks: 417
Thanked 3,923 Times in 3,607 Posts
Are you talking of file names or file contents to strip?
    #4  
Old Unix and Linux 03-05-2013   -   Original Discussion by pasc
pasc's Unix or Linux Image
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 7 January 2018, 4:54 PM EST
Posts: 141
Thanks: 26
Thanked 1 Time in 1 Post
Just the filenames.
Sponsored Links
    #5  
Old Unix and Linux 03-05-2013   -   Original Discussion by pasc
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 24 May 2018, 12:44 PM EDT
Location: Lancashire, UK
Posts: 3,535
Thanks: 1,558
Thanked 692 Times in 622 Posts
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
Sponsored Links
    #6  
Old Unix and Linux 03-05-2013   -   Original Discussion by pasc
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 May 2018, 3:04 PM EDT
Location: Saskatchewan
Posts: 22,680
Thanks: 1,179
Thanked 4,324 Times in 3,987 Posts
Quote:
Originally Posted by pasc View Post
Just the filenames.
Oh.

Well that's simpler, I guess. Linux

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.
Sponsored Links
    #7  
Old Unix and Linux 03-05-2013   -   Original Discussion by pasc
Corona688's Unix or Linux Image
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 25 May 2018, 3:04 PM EDT
Location: Saskatchewan
Posts: 22,680
Thanks: 1,179
Thanked 4,324 Times in 3,987 Posts
Quote:
Originally Posted by rbatte1 View Post
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.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
cgi script to print all .png files on a single page jeffersno1 Shell Programming and Scripting 3 06-07-2010 02:35 AM
Remove the characters from the file Kattoor Shell Programming and Scripting 6 02-16-2010 12:48 AM
How to remove Ctlr-M characters from file from a unix script akashtcs Shell Programming and Scripting 2 08-18-2009 04:11 AM
SUPER simple bash script to repeat a command... robfindlay Shell Programming and Scripting 6 03-23-2009 04:12 PM
Script to find and remove characters Zerby Shell Programming and Scripting 5 01-30-2008 01:16 AM



All times are GMT -4. The time now is 03:55 AM.