How to modify file's date programmaticaly? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have some image files with the wrong date (date of file creation, the value that is shown by ls -l), because it was set wrong in the camera. How can I increment the date by two days in a script changing all *.jpg files in a directory? Bash, Perl, what ever runs on a Linux machine and is appropriate for the job would be fine.
Searching the web I found that touch is used to manipulate date, but I did not found a way incrementing it by two days, while preserving the time.
Thank you.

I guess that instead of modifying the date of the file (like all other responses #this time), you would like to modify the metadatas, so see this page : http://savvyadmin.com/fixing-dates-in-image-exif-tag-data-from-linux/
you have to use jhead (or exiv2) like this :
jhead -ts2003:01:01-00:00:00 image.jpg
Last but not least, there's a special switch -ta to modify directly the date : ex. for 2 days later :
for i in *.jpg; do jhead -ta+48:00 "$i"; done

Use touch to change modtime.
Use date to operate on the date.
Untested:
for f in *jpg; do
mtime=`date -r $f`
nextt=`date "$mtime + 2 days"`
touch -d "$nextt" $f
done

touch is the tool for the job.
for file in P123*.JPG ; do
touch --date="$(date -r $file) + 2 days" $file
done

Related

Add rows in an excel file with a shell script [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 days ago.
Improve this question
I'm trying to create a shell script that creates an excel output file and add data in it.
I don't know how to add rows in this excel file. The goal being that the data will be added in separate cells.
I tried many instruction that i found in the web, but none worked for me.
the file after my script would be like below:
Is there an instruction to do this please?
Thanks for your help
This code worked for me:
touch Output.xls
chmod 777 Output.xls
printf "Date\tTotal number\tSuccessful number\tFailed numbe\n" >> Output.xls
printf "2016_05_11\t20\t5\t15\n" >> Output.xls
printf "2016_06_30\t30\t16\t14\n" >> Output.xls
The output file is as below:
enter image description here

How do i change bi-us-rds-September text value in a file to bi-us-rds- + current date with september as month name? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
This post was edited and submitted for review 12 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
i have a file which contains few lines of code
identifier = "bi-us-rds-15september"
i have to change "bi-us-rds-15september" with "bi-us-rds-current date & current month " .
For example - "bi-us-rds-15september" with "bi-us-rds-18september .
I want to accomplish this using task shell script but i am not good with scripting .
Just use the date format
$ identifier="bi-us-rds-`date +%d%B`"
$ echo $identifier
bi-us-rds-18September
I'd suggest maybe using https://www.tutorialkart.com/bash-shell-scripting/bash-date-format-options-examples/
Also fyi your question is a bit unhelpful - I'd suggest next time at least offer your current script so we can be more precise with the assistance.
edit: removed the extra hyphen just so it matches your exact output required
edit: re: your comment...
$replace=Hi
$replacewith="Hey"
$ echo "Hi how are you?" | sed -e "s/$replace/$replacewith/g"
Hey how are you?

Restructuring the directories in linux/unix [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have several directories structured like this in a parent directory:
/app/bpp/cpp/dpp/ASM/Report
/ghh/hhh/hhh/ASM/Report
/hh/ASM/Report
As we see above, all the ASM directories have Report directories in them along with other sub directories and files. I want a separate directory that has a parent directory to ASM (with ASM only), and ASM with Report directory in it. The result should look like this:
/dpp/ASM/Report
/hhh/ASM/Report
/hh/ASM/Report
It's not absolutely clear what you are asking; do you want to make a copy of the initial directories; do you want rather to move the initial directory to a new location? (Since you seem to want something related to "shell script" you should also tag your question with these words).
The best would probably to start with find; the following command:
find / -type d -name Report
will list all directories called Report; you could pipe the output of this command to grep in order to select those ending with /ASM/Report with:
find / -type d -name Report | grep "\/ASM\/Report$"
this would give to you a good starting point for detecting the directories to be moved/copied.
You can also use the -exec option of find for directly perform some action on a file or directory found by the command. You should type man find in order to see all the power of this tool.
It looks like you will have to search in the whole filesystem; thus find may print some warnings (related to permissions), but it shouldn't hurt; you can discard these warnings (if any) by ending the find command with 2>/dev/null for discarding the stderr stream (the error messages).

Portable bourne shell script without using functions of modern shells as bash, ksh, zsh etc [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
First of all I want thank all of you who will help me solve this. I have an exam tomorrow and I have to prepare this script for the exam. I am really new to linux and those bourne shell script.
My project should be a portable bourne shell script which scans a directory for the following files: header.txt, footer.txt and content.txt. The content of the files should be read but ignoring the lines starting with # and this content should be used for generating an HTML page with the following header, footer and content. This files can contain any text and/or HTML code but the cannot contain head and body tags. When scanning the directory the script have to compare the date of the last change of the files (header.txt, footer.txt and content.txt) with the date of the last change of the HTML page (if you have one already) and if the date of the last edit on the files is newer than the one on the HTML page the script should generate a new HTML page with the latest content.
Guys thank you very much as this is very important for me. Please help me getting this done.
Thank you very much!
To remove lines beginning with # try this:
grep -v "^#" file
To remove lines that may contain spaces (or blank characters) before a #:
grep -v "^[[:blank:]]*#" file

Error in shell script and how to write to a file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am writing a shell script that is extracting the data from a command:
I have tried running the script in both the vi and vim editor. But everything in vain.
Please help me out. And how write the output of this in a file.
It may be noted that this is just a starting point so the script will produce multiple files so
I cannot write:
Script_name > filename
I think this question is fine now, the input file is good enough after edit, I can fully understand what you ask for now.
With awk, you need learn to use 2-d array, it will simplify the code.
awk 'BEGIN{print "Instance id Name Owner Cost.centre"}
/TAG/{split($0,a,FS);a[4]=tolower(a[4]);$1=$2=$3=$4="";b[a[3],a[4]]=$0;c[a[3]]}
END{for (i in c) printf "%-18s%-26s%-14s%-20s\n",i,b[i,"name"],b[i,"owner"],b[i,"cost.center"]}' file
Instance id Name Owner Cost.centre
i-e1cfc499 Memcached
i-7f4b9300 Test_LB01_Sachin
i-c4260db8 Rishi_Win_SAML Rishi Pandey
i-fb5ca283 CLIQR-DO NOT TOUCH mataa 1234

Resources