Hello, I have a question about grep, okay yes is not direct Arch but I not find a information and here on list sure some profis with grep. The folder structure: content/de/blog/*.md content/fr/blog/*.md content/en/blog/*.md content/ru/blog/*.md To know which articles I have translate I grep through dates: grep -e "2019-10-1" content/blog/de (for the dates between 10 and 19) I become: grep -e "2019-10-1" content/de/blog/* content/de/blog/file1.md:date: 2019-10-10 content/de/blog/file2.md:date: 2019-10-12 content/de/blog/file3.md:date: 2019-10-14 content/de/blog/file4.md:date: 2019-10-16 Now is my question, How can I do the same in the other folders and all those that exist with the same date are hidden and when no file is present give out the file which is missing in other folders sort by date. The name of file is sure other, but the date is ever the same. grep -e "2019-10-1" content/en/blog/* No output > all files translated grep -e "2019-10-1" content/fr/blog/* content/de/blog/file4.md:date: 2019-10-16 > file is missed grep -e "2019-10-1" content/ru/blog/* content/de/blog/file3.md:date: 2019-10-14 > file is missed content/de/blog/file4.md:date: 2019-10-16 > file is missed Grep to the first folder (de) as a comparison to the others (en,fr,ru). I had try it with diff but it want not work. Would be great there is a idea. Thank you for help. Silvio
On Mon, Oct 14, 2019 at 3:48 PM siefke_listen@web.de <siefke_listen@web.de> wrote:
Hello,
I have a question about grep, okay yes is not direct Arch but I not find a information and here on list sure some profis with grep.
The folder structure:
content/de/blog/*.md content/fr/blog/*.md content/en/blog/*.md content/ru/blog/*.md
To know which articles I have translate I grep through dates:
grep -e "2019-10-1" content/blog/de (for the dates between 10 and 19)
I become:
grep -e "2019-10-1" content/de/blog/* content/de/blog/file1.md:date: 2019-10-10 content/de/blog/file2.md:date: 2019-10-12 content/de/blog/file3.md:date: 2019-10-14 content/de/blog/file4.md:date: 2019-10-16
Now is my question,
How can I do the same in the other folders and all those that exist with the same date are hidden and when no file is present give out the file which is missing in other folders sort by date. The name of file is sure other, but the date is ever the same.
grep -e "2019-10-1" content/en/blog/* No output > all files translated
grep -e "2019-10-1" content/fr/blog/* content/de/blog/file4.md:date: 2019-10-16 > file is missed
grep -e "2019-10-1" content/ru/blog/* content/de/blog/file3.md:date: 2019-10-14 > file is missed content/de/blog/file4.md:date: 2019-10-16 > file is missed
Grep to the first folder (de) as a comparison to the others (en,fr,ru).
I had try it with diff but it want not work.
Would be great there is a idea.
Thank you for help.
Silvio
I'm having a very difficult time deciding what you are asking, but perhaps this is helpful. It sounds like you want to make sure each language has the same files in it? For instance, given the existence of the files: content/en/blog/file1.md content/en/blog/file2.md content/en/blog/file3.md You want some sort of warning to be issued if only the following files exist in another directory: content/de/blog/file1.md content/de/blog/file3.md Is that correct? If so, you'll do something like for file in content/en/blog/*.md; do basefile=$(basename "$file" .md) if [[ ! -e content/de/blog/"$basefile" ]]; then echo "German is missing $basefile"; fi; done; Perhaps? Maybe instead you're saying that the dates present in one language should also be present in another language? That would be a pretty different solution with which I'm happy to help if you indicate such a desire.
Hello,
for file in content/en/blog/*.md; do basefile=$(basename "$file" .md) if [[ ! -e content/de/blog/"$basefile" ]]; then echo "German is missing $basefile"; fi; done;
Perhaps?
Basename will not work cause the file name have different names in the languages blog folder. Only date is what can be used at all because this stand in header of every markdown field.
Maybe instead you're saying that the dates present in one language should also be present in another language? That would be a pretty different solution with which I'm happy to help if you indicate such a desire.
Yes the dates are ever present. -- Thank you & Nice day Silvio
Hi Silvio, $ grep ^ */* de/1.md:date: 2019-10-10 de/2.md:date: 2019-10-12 de/3.md:date: 2019-10-14 de/4.md:date: 2019-10-16 en/1.md:date: 2019-10-10 en/2.md:date: 2019-10-12 en/3.md:date: 2019-10-14 en/4.md:date: 2019-10-16 fr/4.md:date: 2019-10-16 ru/3.md:date: 2019-10-14 ru/4.md:date: 2019-10-16 $ $ grep -hm1 '^date:' */* | > sort -Vu | > while read -r d; do > for l in ??; do > fgrep -qrx "$d" $l || echo "$d $l" > done > done | > sed 's/^date: //' | > sort 2019-10-10 fr 2019-10-10 ru 2019-10-12 fr 2019-10-12 ru 2019-10-14 fr $ -- Cheers, Ralph.
On Mon, 14 Oct 2019 16:16:43 -0400 Aaron Laws via arch-general <arch-general@archlinux.org> wrote:
for file in content/en/blog/*.md; do basefile=$(basename "$file" .md) if [[ ! -e content/de/blog/"$basefile" ]]; then echo "German is missing $basefile"; fi; done;
Is it possible this do with date? As Comparison with dates. Silvio
Hey hey Silvio, hm this looks more like a challenge for a whole script. I can script, but I'm not always the most efficient. If your .md files always look the same, i.e. there is always the exact line "date: yyyy-mm-dd" and you can be sure that one script folder will have all articles, because they are originally written in that language, I'd have an idea. Say your articles are all created in German: grep -e "date: 2019-10-1" content/de/blog/*.md >orig.list LINES=`wc -l orig.list | awk '{ print $2 }'` # get number of entries # do the same for the ohter folders: grep -e "date: 2019-10-1" content/en/blog/*.md >en.list grep -e "date: 2019-10-1" content/fr/blog/*.md >fr.list # complete for other folders # now check CURLINE=1 while [[ $CURLINE -le $LINES ]]; do CURDATE=`sed -n ${CURLINE}p orig.list # get an article date for FILE in en.list fr.list ru.list and_so_on; do COUNT=`grep -c -e "${CURDATE}" ${FILE} if [[ $COUNT -eq 0 ]]; then # not found in translation echo ${CURDATE} missing in ${FILE}" >missing.files; fi; done let CURLINE=CURLINE+1; # go to next original date done rm *.list # remove your temporary files You can beautify the echo line, at the moment this would write something like: date: 2019-10-12 ru.list But it should do. I'm sure a more elegant script can be written. Best wishes, Jeanette -- * Website: http://juliencoder.de - for summer is a state of sound * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g * SoundCloud: https://soundcloud.com/jeanette_c * Twitter: https://twitter.com/jeanette_c_s * Audiobombs: https://www.audiobombs.com/users/jeanette_c * GitHub: https://github.com/jeanette-c I thought love was just a tingling of the skin <3 (Britney Spears)
Hello, On Mon, 14 Oct 2019 22:23:49 +0200 (CEST) "Jeanette C. via arch-general" <arch-general@archlinux.org> wrote:
Hey hey Silvio, hm this looks more like a challenge for a whole script. I can script, but I'm not always the most efficient.
Yes you right I had think it would be one line :). No worried I search not efficient, it will be only a help in the daily hobby project. Every time manuell run grep make sick on a computer which are build to make our life easier :)
If your .md files always look the same, i.e. there is always the exact line "date: yyyy-mm-dd" and you can be sure that one script folder will have all articles, because they are originally written in that language, I'd have an idea.
Yes this files are markdown text files with a header and the content text. --- title: "Title" date: 2019-10-15 tags: "Gesellschaft" shorttext: "" draft: false lang: de cover: "society" --- So date is in every file and ever in same format because the date formatting make hugo when build the pages.
Say your articles are all created in German: grep -e "date: 2019-10-1" content/de/blog/*.md >orig.list LINES=`wc -l orig.list | awk '{ print $2 }'` # get number of entries # do the same for the ohter folders: grep -e "date: 2019-10-1" content/en/blog/*.md >en.list grep -e "date: 2019-10-1" content/fr/blog/*.md >fr.list # complete for other folders
This work it give files and content like: $ cat de.list content/de/blog/die-grünen-heuchler.md:date: 2019-10-16 content/de/blog/die-killer.md:date: 2019-10-17
# now check CURLINE=1 while [[ $CURLINE -le $LINES ]]; do CURDATE=`sed -n ${CURLINE}p orig.list # get an article date for FILE in en.list fr.list ru.list and_so_on; do COUNT=`grep -c -e "${CURDATE}" ${FILE} if [[ $COUNT -eq 0 ]]; then # not found in translation echo ${CURDATE} missing in ${FILE}" >missing.files; fi; done let CURLINE=CURLINE+1; # go to next original date done rm *.list # remove your temporary files
But this will not work. There is no output at end with a bit playing it run endless or there come Syntax Errors. But an Idea is born. -- Nice Day & Thank you Silvio
Hi Silvio,
How can I do the same in the other folders and all those that exist with the same date are hidden and when no file is present give out the file which is missing in other folders sort by date. The name of file is sure other, but the date is ever the same.
The requirement is unclear. Given this input, $ grep ^ */* de/1.md:date: 2019-10-10 de/2.md:date: 2019-10-12 de/3.md:date: 2019-10-14 de/4.md:date: 2019-10-16 en/1.md:date: 2019-10-10 en/2.md:date: 2019-10-12 en/3.md:date: 2019-10-14 en/4.md:date: 2019-10-16 fr/4.md:date: 2019-10-16 ru/3.md:date: 2019-10-14 ru/4.md:date: 2019-10-16 $ what output do you require? -- Cheers, Ralph.
participants (4)
-
Aaron Laws
-
Jeanette C.
-
Ralph Corderoy
-
siefke_listen@web.de