#linking standard output to standard input using json file
63 messages · Page 1 of 1 (latest)
could you give a small snippet from the json file and the expected output?
you need to grep for the specific filename then likely use awk in some way to strip out the commas and braces then pipe that into touch
in all honesty if you know python itd probably be easier to just use it
jq is a decent tool for this, but Anmac hasn't yet told us the final goal, only a mid-step goal
which is kinda like the xy problem
https://xyproblem.info/
assuming jq searches for a key and spits out a value in a json file just jq <key> | strip out bad characters | touch
if jq just outputs whats within the quotes then just jq <key> | touch
touch accepts standard input, but does not output anything (unless there's an option to make it do that)
touch is a command meant for updating timestamps on files. Although you can use it to create files, that is not what it is meant for and probably should not be used for that purpose, but that is a whole debate.
specific file name?
testIfThere=$(ls /home/Idk/some/file)
if [ -z $testIfThere ]; then
false
else
what do you want to do?
fi
"what do you want to do?"
exactly, problem is unclear.
do you mean read from the file?
touch -m -d -@"1" '/mnt/u/filename.ext'
jq -r .files[0].DateModified,.files[0].FileName '/mnt/c/Users/username/Downloads/PHOTO_INFO.json'
output:
1598544616000
IMG-20200827-WA0011.jpeg
so basically, take the lines from 2) and substitute it into 1)
touch -m -d -@"1598544616" '/mnt/u/IMG-20200827-WA0011.jpeg'
minus 3 0's from this time 1598544616000 > 1598544616 (10 digit number only)
Actually better yet, how can I search for a filename or path and then have it automatically get the date modified from the json ?
this is a more updated question
instead of searching by index in [#] number, it would be easier if I search by name and it gives the datemodified field
look for files matching this path
oof that sounds way more challenging to get a human readable date modified
wait
does the JSON match ls -lt
ls can list by date modified - does the JSON match ls -lt?
problem: if you update name, then the file might update date modified
unless you mount your root file system as noatime or whatever before modifying name, or using a tool that doesn't update date modified
or is just searching with ls -lt enough?
this is what the output of ls -lt may look like
is this used with wsl2 on windows ?
I've hardly ever used Windows so you'll have to find that out
there's 586 files to change the dates
Im using windows subsystem for linux so it seems like it can do much of what linux can on windows
why do you want to change the dates?
also how would you force it not to update to today's date?
samsung smart switch backup on PC doesn't retain the android phone's original date modified, it makes all the files the date of backup on PC. The original date modified as in android was recorded in the PHOTO_INFO.json file hence why I want to revert it back to original
oh
by using touch command to change only the date modified
unless I can test something where, if I restore part of the backup -- whatsapp images back into another android phone and then backup that specific part of the phone with linux will it retain the original timestamp ?
probably won't get the OG time stamp unless it were maybe copied directly from the older Android phone
sounds tough
I'd probably have to have that JSON myself and try to script something up
the problem is that the whatsapp files don't exist on the phone anymore, it was backed up to PC with it's json file and then the pictures were deleted in 2021, so the pictures are not on the phone with the original dates.
i can send it to
oh boy, single line
that'd sure take some processing to put the awk command to work
maybe awk gsub of , as field separator
sorry, maybe I'll try once I get my clipboard history program all integrated like an app
okay
I'm going to try to restore backup to this s21 for a small sample of files and see what changes
There has to be a faster way to get those timestamps and filenames
as u can see everything above the blue box, is what i changed manually from the json file and wsl2, and all the highlighted files are all backed up from samsung smart switch back in 2021
all having the same dates
u can download the .json file
after I tackle a bunch of my own things, sure
okay. FYi, I can import the .json file into exel. Can I do something with excel ?
okay weird, samsung smart switch said that there are no files in the backup. It didn't recognize the backup (even though its from my brother's PC). Maybe he didn't back it up properly
solved it using excel lol
using this kind of syntax:
="touch -m -d -@"&CHAR(34)&LEFT([@[Column1.DateModified]],LEN([@[Column1.DateModified]])-3)&CHAR(34)&" "&CHAR(34)&[@[Column1.FileName]]&CHAR(34)
imported the PHOTO_INFO.json file into power data query and then formatted it as a table, then under Column1.FilePath, I filtered to /mnt/sdcard/WhatsApp/Media/WhatsApp Images to show only whatsapp files, then i made a new column with the above syntax and just copy and paste all the rows into wsl2 linux and then it updated all the date modified of all the files
Although I'm not really sure why there are duplicate entries for each touch command
Here is what the excel table looks like:
so you figured it out?