LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-10-2016, 05:34 PM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Rep: Reputation: Disabled
Simplifying a script


I have a script using Exiftool to remove the software tag, comment header line and date data (in both EXIF and IPTC) from files saved with Gimp 2.8 or 2.9. I want to simplify it so the user needn't go any further than to type the name of the script and the name of the file they want to strip.

The script is called degimp.
Code follows.
Code:
#!/bin/bash -i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

echo -e "What file do you want to 'De-GIMP'?"
read -e item
file1=$item
if [ -f "$file1" ]; then
	exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $file1
	echo "File $file1 is now De-GIMPed."
	echo "Check it for yourself with any good tool."
else
	echo "Your file is not in this directory."
	echo "No file to de-GIMP."
	exit 0
fi
IFS=$SAVEIFS
I'm still a little sketchy w/re the whole "$1" thing. Would a line at the top like
Code:
file1="$1"
work in place of the current prompt?

Carver

Last edited by L_Carver; 12-10-2016 at 05:35 PM.
 
Old 12-10-2016, 05:54 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Code:
$./FileName argument argument
  $0          $1       $2
build in Bash assignments for variables.

Code:

Removed this line #!/bin/bash -i, <- I do not know what that -i is for,
 but it kept restarting my shell, 
so I replaced with this


#!/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

#echo -e "What file do you want to 'De-GIMP'?"
#read -e item

echo "$0"
echo "$1"


#file1="item"


if [ -f "$1" ]; then
#	exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $1
	echo "File $1 is now De-GIMPed."
	echo "Check it for yourself with any good tool."
else
	echo "Your file is not in this directory." 

	echo "No file to de-GIMP."
	exit 0
fi
IFS=$SAVEIFS
just type in the script name and then file name hit enter.


Code:
userx@voided1.what~>> ./xtest textCattwo
./xtest
textCattwo
File textCattwo is now De-GIMPed.
Check it for yourself with any good tool.

Last edited by BW-userx; 12-10-2016 at 06:16 PM.
 
1 members found this post helpful.
Old 12-10-2016, 06:23 PM   #3
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
Code:
#!/bin/bash

[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $$(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\nCheck it for yourself with any good tool."; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."

Last edited by c0wb0y; 12-10-2016 at 06:43 PM.
 
Old 12-10-2016, 06:31 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
if you want to do more error checking, say for the proper file type.

Code:
#!/bin/bash 


SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

echo "$0"
echo "$1"

                c=$1
	 
		ext=${c##*.}
		echo "ext $ext"
		
		

if [[ -f "$1" && "$ext" == 'mp4' || "$ext" == 'mkv' ]]; then


#	exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $file1
	echo "File $1 is now De-GIMPed."
	echo "Check it for yourself with any good tool."
else
	echo "Your file is not in this directory."
	echo "No file to de-GIMP."
	

      exit 1  <- error is not exit 0 
fi
#IFS=$SAVEIFS
if it is the wrong extension then it gets error'ed out.

Code:
userx@voided1.what~>> ./xtest textCattwo.oop
./xtest
textCattwo.oop
ext oop
Your file is not in this directory.
No file to de-GIMP.

note to @c0wb0y

make that one a one liner.

Last edited by BW-userx; 12-10-2016 at 06:48 PM.
 
Old 12-10-2016, 06:57 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
@c0wb0y

I had to fix your code, I just added mine to yours before checking yours.

Code:
userx@voided1.what~>> ./xtest textCattwo.mkv
./xtest
textCattwo.mkv
ext mkv
./xtest: line 20: syntax error near unexpected token `('
./xtest: line 20: `[[ -f $1  && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $$(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."'
Code:
#!/bin/bash 

#-i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

c=$1
ext=${c##*.}
echo "ext $ext"
		

[[ -f $1  && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."


IFS=$SAVEIFS
 
Old 12-10-2016, 07:02 PM   #6
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
I know. Those damn extra double quotes and $ sign. These fat fingers.

Last edited by c0wb0y; 12-10-2016 at 07:03 PM.
 
Old 12-10-2016, 07:32 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by c0wb0y View Post
I know. Those damn extra double quotes and $ sign. These fat fingers.
I fix that then ran it and it still throws an error, so I fixed that and I am not sure what type of files he is using. but that Date I did not fix. getting this error

Code:
userx@voided1.what~>> ./xtest Pitch.Perfect.2.2015.720p.mp4
ext mp4
Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in IFD0:ModifyDate (PrintConvInv)
Error: Truncated mdat atom - Pitch.Perfect.2.2015.720p.mp4
Your file is not in this directory.
No file to de-GIMP.
using this code.

Code:
#!/bin/bash 

#-i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

c=$1
ext=${c##*.}
echo "ext $ext"
		

#[[ -f $1  && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $(date +%F).$1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."


#### this one 
[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate="$(date +%F)" $1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."

IFS=$SAVEIFS

Just a date format issue NBD, I changed it to this
Code:
-ModifyDate="$(date +%F%T)" $1  <-- exiftool needs file name last to process it.
removing the filename because it kept looking for the annotated file and not the one added on the command line.

Code:
userx@voided1.what~>> ./xtest Pitch.Perfect.2.2015.720p.mp4
ext mp4
Error: File not found - 2016-12-10.Pitch.Perfect.2.2015.720p.mp4
Error: Truncated mdat atom - Pitch.Perfect.2.2015.720p.mp4
Your file is not in this directory.
No file to de-GIMP.
I do not know what type of file he is actually working with, but just using this line(s)
Code:
#!/bin/bash 

#-i
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

c=$1
ext=${c##*.}
echo "ext $ext"
		

[[ -f $1  && "$ext" == 'mp4' || "$ext" == 'mkv' ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate="$(date +%F%T)" $1 && echo -e "File $1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."

#[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate="$(date +%F%T)" $1 && echo -e "File $file1 is now De-GIMPed.\n"Check it for yourself with any good tool.""; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."

IFS=$SAVEIFS
keeping in that error checking for extensions type with and without it I still get the same error.

Code:
userx@voided1.what~>> ./xtest Pitch.Perfect.2.2015.720p.mp4
ext mp4
Error: Truncated mdat atom - Pitch.Perfect.2.2015.720p.mp4
Your file is not in this directory.
No file to de-GIMP.
so it kicks it out and sends the last message.

now if he, the OP can figure all of this out, that'd be a good thing.

Last edited by BW-userx; 12-10-2016 at 07:34 PM.
 
Old 12-10-2016, 07:44 PM   #8
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 241

Original Poster
Rep: Reputation: Disabled
Thanks for all the help and suggestions...

After a little more Google-ing and getting friendly with Stack Exchange, I came up with this re-edit of my original script:
Code:
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

file1="$1"

if [ -f "$file1" ]; then
	exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $file1
	echo "File $file1 is now De-GIMPed."
	echo "Check it for yourself with any good tool."
else
	echo ""
	echo "No file to de-GIMP."
	exit 0
fi
IFS=$SAVEIFS
Tested it six times already. No errors (a surprise) and the tags are indeed removed.

I have yet to test the Your file is not in this directory. Which seems unnecessary since the user is naming the file to be de-gimp'ed. I may just edit it out. That sort of thing fits better with a "while read line" kind of loop, which was what I was trying to get away from.

I kept the original script in my execution path, of course and renamed it degimp2. degimp seems more appropriate for the one where the filename follows the command to start the script. I was surprised to not get any bash error messages. I guess the changes I made were up to spec for bash 4.3.

Carver

Last edited by L_Carver; 12-10-2016 at 07:47 PM. Reason: Flow of sentences; spelling,
 
Old 12-10-2016, 07:56 PM   #9
c0wb0y
Member
 
Registered: Jan 2012
Location: Inside the oven
Distribution: Windows
Posts: 417

Rep: Reputation: 74
Hah! Problem with me writing on-the-fly and not reading what those arguments for.

Code:
#!/bin/bash

[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $1 && echo -e "File $file1 is now De-GIMPed.\nCheck it for yourself with any good tool."; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."
 
Old 12-10-2016, 07:59 PM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by c0wb0y View Post
Hah! Problem with me writing on-the-fly and not reading what those arguments for.

Code:
#!/bin/bash

[[ -f $1 ]] && { exiftool -fast5 -overwrite_original_in_place -P -q -Software= -Comment= -IPTC:DateCreated= -IPTC:TimeCreated= -ModifyDate= $1 && echo -e "File $file1 is now De-GIMPed.\nCheck it for yourself with any good tool."; } ||  echo -e "Your file is not in this directory.\nNo file to de-GIMP."
I think he wanted to make everything void and null .. anyways, he went to another store to get what he needed after asking us.
 
Old 12-11-2016, 03:20 PM   #11
Fat_Elvis
Member
 
Registered: Oct 2016
Distribution: FreeDOS 1.2
Posts: 309

Rep: Reputation: 92
I like Cowboy's script the best but why oh why is it all in one line?

To save space?
 
Old 12-11-2016, 03:30 PM   #12
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by Fat_Elvis View Post
I like Cowboy's script the best but why oh why is it all in one line?

To save space?
that is the thing about coding, you can one line it. you still need to declare /bin/bash and you output, I just added error checking file types.
 
Old 12-11-2016, 04:15 PM   #13
Fat_Elvis
Member
 
Registered: Oct 2016
Distribution: FreeDOS 1.2
Posts: 309

Rep: Reputation: 92
Quote:
Originally Posted by BW-userx View Post
that is the thing about coding, you can one line it. you still need to declare /bin/bash and you output, I just added error checking file types.
I understand the script, just found his choice to "one line" it funny. Which was probably the intention.
 
Old 12-11-2016, 05:03 PM   #14
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (current), FreeBSD, Win10, It varies
Posts: 9,952

Rep: Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148Reputation: 2148
Quote:
Originally Posted by Fat_Elvis View Post
I understand the script, just found his choice to "one line" it funny. Which was probably the intention.
it is just a coding style. if you can do it in one line rather then many lines. well then what is to be said of that?
 
Old 12-11-2016, 05:27 PM   #15
Fat_Elvis
Member
 
Registered: Oct 2016
Distribution: FreeDOS 1.2
Posts: 309

Rep: Reputation: 92
Quote:
Originally Posted by BW-userx View Post
it is just a coding style. if you can do it in one line rather then many lines. well then what is to be said of that?
Didn't mean to be critical, just humorous.

Eh, and I'd need one of those super wide screens to fit that in one line in a text editor. Hehe.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash - simplifying an array Lucien Lachance Programming 15 08-02-2013 05:26 PM
[SOLVED] simplifying awk command froggins Linux - Newbie 5 02-24-2011 04:33 AM
Lighttpd URL simplifying alsharifhoussam Linux - Server 5 11-16-2009 07:20 AM
simplifying wine Four Linux - Newbie 6 12-28-2005 05:02 PM
Adding only new text/simplifying lists invisible_ink Linux - Newbie 1 11-24-2004 02:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration