#linking standard output to standard input using json file

63 messages · Page 1 of 1 (latest)

lusty mural
#

Hello everyone !!

I have a json file and I want to use linux to search a particular filename and pipe it's output its key value into another touch command. How can I do this ?

basically, which commands use standard input and standard output ?

vast kiln
#

could you give a small snippet from the json file and the expected output?

torpid dew
#

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

vast kiln
#

jq is a decent tool for this, but Anmac hasn't yet told us the final goal, only a mid-step goal

torpid dew
#

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)

vast kiln
#

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.

sage hornet
#

specific file name?

#

testIfThere=$(ls /home/Idk/some/file)
if [ -z $testIfThere ]; then
false
else
what do you want to do?
fi

vast kiln
sage hornet
#

do you mean read from the file?

lusty mural
#

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

sage hornet
#

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

lusty mural
#

is this used with wsl2 on windows ?

sage hornet
#

I've hardly ever used Windows so you'll have to find that out

lusty mural
#

there's 586 files to change the dates

lusty mural
sage hornet
#

disgusting limitation

#

unless that wasn't a typo

sage hornet
#

also how would you force it not to update to today's date?

lusty mural
# sage hornet why do you want to change the dates?

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

sage hornet
#

oh

lusty mural
lusty mural
# sage hornet oh

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 ?

sage hornet
#

probably won't get the OG time stamp unless it were maybe copied directly from the older Android phone

sage hornet
#

I'd probably have to have that JSON myself and try to script something up

lusty mural
sage hornet
#

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

lusty mural
#

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

lusty mural
sage hornet
#

after I tackle a bunch of my own things, sure

lusty mural
#

okay. FYi, I can import the .json file into exel. Can I do something with excel ?

lusty mural
#

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

lusty mural
#

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:

sage hornet
#

so you figured it out?