Why does glob expansion behave differently when file extensions are different?
I have a program which takes multiple files as command line arguments. These files are contained in a folder "mtx", and they all have ".mtx" extension. I usually call my program from the command line as
Now, I have another folder "roa", which has the same files as "mtx", except that they have ".roa" extension, and for these I call my program with
Since these folders contain the same exact file names except for the extension, I thought thought "mtx/*" and "roa/*" would expand the files in the same order. However, there are some differences in these expansions.
To prove these expansions are different, I created a toy example:
EDIT: Rather than running the code below, this behavior can be demonstrated as follows:
1) Make a directory "A" with subdirectories "mtx" and "roa"
2) In mtx create files called "G3.mtx" and "g3rmt3m3.mtx"
3) in roa, create these same files but with .roa extension.
4) From "A", run "echo mtx/*" and "echo roa/*". These should give different results.
END EDIT
https://github.com/Optimization10/GlobExpansion
The output of this code is two csv files, one with the file names from the "mtx" folder as they are expanded from "mtx/*", and one with file names from the "roa" as expanded from "roa/*".
As you can see in the Google sheet, lines 406 and 407 are interchanged, and lines 541-562 are permuted.
https://docs.google.com/spreadsheets/d/1Bw3sYcOMg7Nd8HIMmUoxXxWbT2yatsledLeiTEEUDXY/edit?usp=sharing
I am wondering why these expansions are different, and is this a known feature or issue?
https://redd.it/1jiwxud
@r_bash
I have a program which takes multiple files as command line arguments. These files are contained in a folder "mtx", and they all have ".mtx" extension. I usually call my program from the command line as
myprogram mtx/*Now, I have another folder "roa", which has the same files as "mtx", except that they have ".roa" extension, and for these I call my program with
myprogram roa/* .Since these folders contain the same exact file names except for the extension, I thought thought "mtx/*" and "roa/*" would expand the files in the same order. However, there are some differences in these expansions.
To prove these expansions are different, I created a toy example:
EDIT: Rather than running the code below, this behavior can be demonstrated as follows:
1) Make a directory "A" with subdirectories "mtx" and "roa"
2) In mtx create files called "G3.mtx" and "g3rmt3m3.mtx"
3) in roa, create these same files but with .roa extension.
4) From "A", run "echo mtx/*" and "echo roa/*". These should give different results.
END EDIT
https://github.com/Optimization10/GlobExpansion
The output of this code is two csv files, one with the file names from the "mtx" folder as they are expanded from "mtx/*", and one with file names from the "roa" as expanded from "roa/*".
As you can see in the Google sheet, lines 406 and 407 are interchanged, and lines 541-562 are permuted.
https://docs.google.com/spreadsheets/d/1Bw3sYcOMg7Nd8HIMmUoxXxWbT2yatsledLeiTEEUDXY/edit?usp=sharing
I am wondering why these expansions are different, and is this a known feature or issue?
https://redd.it/1jiwxud
@r_bash
GitHub
GitHub - Optimization10/GlobExpansion
Contribute to Optimization10/GlobExpansion development by creating an account on GitHub.
What's a good collection or source of bash noscripts that you can read to sharpen your knowledge of noscripting techniques
Hello my fellow bashelors/bashelorettes . Basically, what the noscript of the post says.
https://redd.it/1jndfqs
@r_bash
Hello my fellow bashelors/bashelorettes . Basically, what the noscript of the post says.
https://redd.it/1jndfqs
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can someone explain this to me?
Why does the in-place replacement seem to work differently?
https://redd.it/1jn5km5
@r_bash
➜ ~ echo ' escaped_input=$(something)' > test.sh
sed -E 's/^(\s)escaped_input=\$\(.*\)$/\1user_input=$(whatever)/' test.sh
sed -iE 's/^(\s)escaped_input=\$\(.*\)$/\1user_input=$(whatever)/' test.sh; cat test.sh
user_input=$(whatever)
escaped_input=$(something)
Why does the in-place replacement seem to work differently?
https://redd.it/1jn5km5
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
If I'm in the wrong place, they can erase it. Excuse me! Has anyone references about this command or program? https: / / linrunner.de / tlp / index.html
Hi I have problem with my laptop battery: at 88% of charge shutdown the laptop without alert me.
I think that I need to calibrate the battery.
this program by command line from my repo Lubuntu works on batteries...
any reference about it?
TLP https://linrunner.de/tlp/index.html
Thank you and regards!
https://redd.it/1jo3yjm
@r_bash
Hi I have problem with my laptop battery: at 88% of charge shutdown the laptop without alert me.
I think that I need to calibrate the battery.
this program by command line from my repo Lubuntu works on batteries...
any reference about it?
TLP https://linrunner.de/tlp/index.html
Thank you and regards!
https://redd.it/1jo3yjm
@r_bash
If I'm in the wrong place, they can erase it. Excuse me! Has anyone references about this command or program? https: / / linrunner.de / tlp / index.html
Hi I have problem with my laptop battery: at 88% of charge shutdown the laptop without alert me.
I think that I need to calibrate the battery.
this program by command line from my repo Lubuntu works on batteries...
any reference about it?
TLP https://linrunner.de/tlp/index.html
Thank you and regards!
https://redd.it/1jo3zhy
@r_bash
Hi I have problem with my laptop battery: at 88% of charge shutdown the laptop without alert me.
I think that I need to calibrate the battery.
this program by command line from my repo Lubuntu works on batteries...
any reference about it?
TLP https://linrunner.de/tlp/index.html
Thank you and regards!
https://redd.it/1jo3zhy
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
how do I make such beautiful warning messages in my noscript like pnpm of NodeJS?
https://redd.it/1jobphj
@r_bash
https://redd.it/1jobphj
@r_bash
OctoWatch - A minimalistic command-line octoprint dashboard
Want to monitor your 3D prints on the command line?
https://preview.redd.it/dr5jp1jv05se1.png?width=759&format=png&auto=webp&s=15aa7483d36c61f3525c56e0d13bb06fa3ec7563
https://preview.redd.it/w4cr4yiv05se1.png?width=762&format=png&auto=webp&s=340d805a21a63fc6d70f4f20b999dc7a682dbb51
OctoWatch is a quick and simple dashboard for monitoring 3D printers, in your network. It uses OctoPrint’s API, and displaying live print progress, timing, and temperature data, ideal for resource-constrained system and a Quick peak at the progress of your prints.
Since i have 2, 3D printers and after customizing their firmware (for faster baud rates and some gcode tweaks, for my personal taste) - i connected them with Raspberry pi zero 2W each. Installed octoprint for each printer so i can control them via network.
Since octoprint is a web UI made with python, and it always takes 5-8 seconds to just load the dashboard. So, I created octowatch - it shows you the current progress with the minimalistic view of the dashboard.
If by chance, you have can use this to test it - your feedback is highly appreciated.
Here's the link to the project: GitHub - TheKvc/octowatch: OctoWatch is a quick and simple dashboard for monitoring 3D printers, in your network. It uses OctoPrint’s API, and displaying live print progress, timing, and temperature data, ideal for resource-constrained system and a Qucik peak at the progress of your prints. 3
*Consider giving it a star on github
Note: This is made in bash, I will work on making it in batch/python as well, But i mainly use linux now...so, that might be taking time. Let me know, if you want this for other platforms too.
https://redd.it/1joljjd
@r_bash
Want to monitor your 3D prints on the command line?
https://preview.redd.it/dr5jp1jv05se1.png?width=759&format=png&auto=webp&s=15aa7483d36c61f3525c56e0d13bb06fa3ec7563
https://preview.redd.it/w4cr4yiv05se1.png?width=762&format=png&auto=webp&s=340d805a21a63fc6d70f4f20b999dc7a682dbb51
OctoWatch is a quick and simple dashboard for monitoring 3D printers, in your network. It uses OctoPrint’s API, and displaying live print progress, timing, and temperature data, ideal for resource-constrained system and a Quick peak at the progress of your prints.
Since i have 2, 3D printers and after customizing their firmware (for faster baud rates and some gcode tweaks, for my personal taste) - i connected them with Raspberry pi zero 2W each. Installed octoprint for each printer so i can control them via network.
Since octoprint is a web UI made with python, and it always takes 5-8 seconds to just load the dashboard. So, I created octowatch - it shows you the current progress with the minimalistic view of the dashboard.
If by chance, you have can use this to test it - your feedback is highly appreciated.
Here's the link to the project: GitHub - TheKvc/octowatch: OctoWatch is a quick and simple dashboard for monitoring 3D printers, in your network. It uses OctoPrint’s API, and displaying live print progress, timing, and temperature data, ideal for resource-constrained system and a Qucik peak at the progress of your prints. 3
*Consider giving it a star on github
Note: This is made in bash, I will work on making it in batch/python as well, But i mainly use linux now...so, that might be taking time. Let me know, if you want this for other platforms too.
https://redd.it/1joljjd
@r_bash
Getting a job without experience
I have my bachelor's degree in Mechatronics Engineering, I graduated in a college in Mexico in 2015.
I did an internship of 6 months when I graduated and after that my family and I relocated to the States. But, since my visa didn't let me to work just to live here I wasn't able to work here until now that I have my permanent residency.
In the meantime I took 2 certifications one in C with Linux bash noscripting and another one in SQL Databases.
I have been applying for a couple of months but haven't had answers from the companies I applied for.
What do you guys think is the best path to get hired?
I would greatly appreciate your advice and suggestions.
https://redd.it/1jp3bj0
@r_bash
I have my bachelor's degree in Mechatronics Engineering, I graduated in a college in Mexico in 2015.
I did an internship of 6 months when I graduated and after that my family and I relocated to the States. But, since my visa didn't let me to work just to live here I wasn't able to work here until now that I have my permanent residency.
In the meantime I took 2 certifications one in C with Linux bash noscripting and another one in SQL Databases.
I have been applying for a couple of months but haven't had answers from the companies I applied for.
What do you guys think is the best path to get hired?
I would greatly appreciate your advice and suggestions.
https://redd.it/1jp3bj0
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Searching in always in the whole history
I search in my bash history, but somehow after I skipped something accidently by pressing:
ctrl + r a second time, I can not find it.
I love the search option, but this is so weird behaviour. Can anybody please explain, why this happens and suggest a solution, so that I can search all the time for everything?
https://redd.it/1jou6sf
@r_bash
I search in my bash history, but somehow after I skipped something accidently by pressing:
ctrl + r a second time, I can not find it.
I love the search option, but this is so weird behaviour. Can anybody please explain, why this happens and suggest a solution, so that I can search all the time for everything?
https://redd.it/1jou6sf
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
An alias for show then edit and then execute? anything like :p for history command but for CLI command.
Hi I'd like to get an alias that let me edit and then <CR> for execute.
I will change the flag --date for -# ¿0? -# day according to the day I want to put with respect to the current day.
The command is this:
alias dd="touch ./markdown$(date --date='-1 day' +%a%-d).md"
Thank you and Regards!
https://redd.it/1jq1qop
@r_bash
Hi I'd like to get an alias that let me edit and then <CR> for execute.
I will change the flag --date for -# ¿0? -# day according to the day I want to put with respect to the current day.
The command is this:
alias dd="touch ./markdown$(date --date='-1 day' +%a%-d).md"
Thank you and Regards!
https://redd.it/1jq1qop
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Where can I read about CLI-colors for understand and learn about it?
Hi, my CLI has 16 colors using neofetch command,
screenshot 1 https://imgbox.com/PEfXpQZ4
where can I read about it?
If I do vim :xtermcolor(a plugin) I have a palette with more colors...
screenshot 2 https://imgbox.com/TugiCQy6
what are the colors I have?
THank you and regards!!!
https://redd.it/1jql3ov
@r_bash
Hi, my CLI has 16 colors using neofetch command,
screenshot 1 https://imgbox.com/PEfXpQZ4
where can I read about it?
If I do vim :xtermcolor(a plugin) I have a palette with more colors...
screenshot 2 https://imgbox.com/TugiCQy6
what are the colors I have?
THank you and regards!!!
https://redd.it/1jql3ov
@r_bash
Imgbox
imgbox - fast, simple image host
Use imgbox to upload, host and share all your images. It's simple, free and blazing fast!
Command substitution, piping
If the following is written in with pipes instead of command substitutions, how would they compare, particularly at the lower level (e.g. do they involve the same # of forks and execs)? And differences in performance in general or other implications.
It's a very simple example, normally I would just use external commands and pipe if it's a one-off to be run on the command line, whereas for noscripts I would like to be more a little more conscious about how to write better bash (beyond simple general optimizations like avoiding excessive unnecessary external commands).
filename="$(realpath "$1")"
dir="${filename%/}"
size="$(du -b "$filename")"
size=$(numfmt --to=iec --format='%0.5f' "${size%% }")
...
https://redd.it/1jqyeg8
@r_bash
If the following is written in with pipes instead of command substitutions, how would they compare, particularly at the lower level (e.g. do they involve the same # of forks and execs)? And differences in performance in general or other implications.
It's a very simple example, normally I would just use external commands and pipe if it's a one-off to be run on the command line, whereas for noscripts I would like to be more a little more conscious about how to write better bash (beyond simple general optimizations like avoiding excessive unnecessary external commands).
filename="$(realpath "$1")"
dir="${filename%/}"
size="$(du -b "$filename")"
size=$(numfmt --to=iec --format='%0.5f' "${size%% }")
...
https://redd.it/1jqyeg8
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Digital footprint and website testing tool recommendations
I'm cybersecurity student and getting into bash noscripting. I want to make my own universal tool to do Digital footprint checks, website vulnerabilitie check network scans and more. I have the website vulnerabilitie check partly done using, curl, nmap, testssl, webanalyse and ffuf. And I am working on retire js and npmjs to find old Java noscripts. What more could I add to this?
Secondly I want to make a Digital footprint check. What tools / FOSS that can be used in bash noscript to do such a scan? are there any api's I need to get? I know that people sometimes use GB's worth of leaked credentials files is there any legal(open to dm's) way to obtain this.
Any more recommendation or other tools someone uses or likes to be made. when most of my tools work I'm thinking to open source everything on a Github
https://redd.it/1jr815b
@r_bash
I'm cybersecurity student and getting into bash noscripting. I want to make my own universal tool to do Digital footprint checks, website vulnerabilitie check network scans and more. I have the website vulnerabilitie check partly done using, curl, nmap, testssl, webanalyse and ffuf. And I am working on retire js and npmjs to find old Java noscripts. What more could I add to this?
Secondly I want to make a Digital footprint check. What tools / FOSS that can be used in bash noscript to do such a scan? are there any api's I need to get? I know that people sometimes use GB's worth of leaked credentials files is there any legal(open to dm's) way to obtain this.
Any more recommendation or other tools someone uses or likes to be made. when most of my tools work I'm thinking to open source everything on a Github
https://redd.it/1jr815b
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
noob in bash, need learn
Hey guys, I’m a student and getting into sysadmin stuff. I heard knowing Bash noscripting is kinda essential, and I really wanna learn it but I’m a total Linux noob and have no clue where to start. Any tips?
And sry for my english, im trying my best haha
https://redd.it/1jrmtqu
@r_bash
Hey guys, I’m a student and getting into sysadmin stuff. I heard knowing Bash noscripting is kinda essential, and I really wanna learn it but I’m a total Linux noob and have no clue where to start. Any tips?
And sry for my english, im trying my best haha
https://redd.it/1jrmtqu
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Need Help for bash noscript
I'm trying to prepare a noscript in bash that books a seat in a library in my city via Affluences but i can't find any API on the web page, my idea was to use the cURL library and send a request to the server of the app, is there any advice or sub you could suggest?
https://redd.it/1jsc5s4
@r_bash
I'm trying to prepare a noscript in bash that books a seat in a library in my city via Affluences but i can't find any API on the web page, my idea was to use the cURL library and send a request to the server of the app, is there any advice or sub you could suggest?
https://redd.it/1jsc5s4
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
ShellCheck problem with sourcing a noscript
I'm using ShellCheck for the first time and I'm getting an error with a line in the noscript being checked which is sourcing another noscript.
My understanding of the ShellCheck documentation is that I should be able to embed a shellcheck directive telling it what to use for a source path.
It's not working.
The relevant lines in my noscript are:
SCRIPT_DIR=$(dirname "$0")
\# shellcheck source-path=SCRIPTDIR
source "$SCRIPT_DIR/bash_env.sh"
I get the following error:
In _setenv.sh line 45:
source "$SCRIPT_DIR/bash_env.sh"
\^-----------------------\^ SC1090: Can't follow non-constant source. Use a directive to specify location.
What am I doing wrong?
Thanks in advance for any help you can give me.
https://redd.it/1jtekj9
@r_bash
I'm using ShellCheck for the first time and I'm getting an error with a line in the noscript being checked which is sourcing another noscript.
My understanding of the ShellCheck documentation is that I should be able to embed a shellcheck directive telling it what to use for a source path.
It's not working.
The relevant lines in my noscript are:
SCRIPT_DIR=$(dirname "$0")
\# shellcheck source-path=SCRIPTDIR
source "$SCRIPT_DIR/bash_env.sh"
I get the following error:
In _setenv.sh line 45:
source "$SCRIPT_DIR/bash_env.sh"
\^-----------------------\^ SC1090: Can't follow non-constant source. Use a directive to specify location.
What am I doing wrong?
Thanks in advance for any help you can give me.
https://redd.it/1jtekj9
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Can anyone suggest me good Bash book filled with small examples only?
Hi everyone,
Can anyone suggest me good Bash book filled with lots of small examples with explanation? . I'm already going on with Advanced Bash Scripting By Mandel sir, and would like to get a book/online resource that has plenty of Bash Examples with explanation to compliment it with Mandel sir's book.
Thanks and Regards
https://redd.it/1jtsqhr
@r_bash
Hi everyone,
Can anyone suggest me good Bash book filled with lots of small examples with explanation? . I'm already going on with Advanced Bash Scripting By Mandel sir, and would like to get a book/online resource that has plenty of Bash Examples with explanation to compliment it with Mandel sir's book.
Thanks and Regards
https://redd.it/1jtsqhr
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
how to combine find and identify? pipe or &&
Hi, I was trying to use these 2 commands together but I fail.
I used find . -type f -name "3434.jpg fine
I used identify ./ fine
how do you combine then?
¿ find -name ###.jpg | identify ??
Thank you and regards!
https://redd.it/1jutpsq
@r_bash
Hi, I was trying to use these 2 commands together but I fail.
I used find . -type f -name "3434.jpg fine
I used identify ./ fine
how do you combine then?
¿ find -name ###.jpg | identify ??
Thank you and regards!
https://redd.it/1jutpsq
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Shell noscript confounding me ...
I've been working on a shell noscript that automates file movements. I'm using the Mac Automator with a Folder action. Drop a file on a folder and the noscript disperses the file to specific folders based on the file extension {or other string the file name}. All works fine except it does not work with image files [.jpg, .jpeg, .png, .dng, .bmp, .gif, .heic files.\] Pages files, txt files, doc files, and most others work, Below is the opening snippet of the noscript, Can anyone see my blunders? Will this tool NOT work with image fiiles?
Even when I isolate this to one type of image file and repeat the block for aaeh type of file, it still fails,
\#start
for f in "$@"
do
DEST="" # Image files NOTE: "bmp" does not work
if [[ $f == *".png"* || $f == *".jpg"* || $f == *".jpeg"* || $f == *".dng"* || $f == *".gif"* || $f == *".heic"* \]\]
then
DEST="Users/dparcher/Documents/Images"
\# text files:
elif [[ $f == *".txt"* \]\]
then
DEST="/Users/dparcher/Documents/TXTFiles"
\# ... etc, (,csv files also do no process?)
\# and finally:
fi
if [[ $DEST != "" \]\]
then
osanoscript -e "display notification \\"Moved $f to $DEST\\""
\# now move the files accordingly
mv $f $DEST
elif
osanoscript -e "display notification \\"$f was NOT moved.\\""
done
{Bang Head Here}
Thanks for any help offered ...
https://redd.it/1jv605d
@r_bash
I've been working on a shell noscript that automates file movements. I'm using the Mac Automator with a Folder action. Drop a file on a folder and the noscript disperses the file to specific folders based on the file extension {or other string the file name}. All works fine except it does not work with image files [.jpg, .jpeg, .png, .dng, .bmp, .gif, .heic files.\] Pages files, txt files, doc files, and most others work, Below is the opening snippet of the noscript, Can anyone see my blunders? Will this tool NOT work with image fiiles?
Even when I isolate this to one type of image file and repeat the block for aaeh type of file, it still fails,
\#start
for f in "$@"
do
DEST="" # Image files NOTE: "bmp" does not work
if [[ $f == *".png"* || $f == *".jpg"* || $f == *".jpeg"* || $f == *".dng"* || $f == *".gif"* || $f == *".heic"* \]\]
then
DEST="Users/dparcher/Documents/Images"
\# text files:
elif [[ $f == *".txt"* \]\]
then
DEST="/Users/dparcher/Documents/TXTFiles"
\# ... etc, (,csv files also do no process?)
\# and finally:
fi
if [[ $DEST != "" \]\]
then
osanoscript -e "display notification \\"Moved $f to $DEST\\""
\# now move the files accordingly
mv $f $DEST
elif
osanoscript -e "display notification \\"$f was NOT moved.\\""
done
{Bang Head Here}
Thanks for any help offered ...
https://redd.it/1jv605d
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community
Replace partial lines of a file with another file's lines
I have a noscript that has the output e.g. (keeping the examples very short):
# date: 2025-04-01T16:31:24-0400
firejail-git 0.9.73.r10.gc66588df8
yt-dlp 2025.03.21
syncthing 1.23.4
libvirt 4.2.1
I want to replace all these lines (comments excluded) with lines in a file whose first field (delimited by space) matches the file's lines' first field and and potentially its second field (if it starts with a number), else add the version number as the second field. Such a file looks like this before replacement:
# date: 2024-04-01T16:31:24-0400
# blah blah blaah
abc 1.234
firejail-git 0.9.72.r10.gc66588df8
yt-dlp
# blah blah blaah
syncthing 1.20.4 # blah blah blah
libvirt
After replacement:
# date: 2025-04-01T16:31:24-0400
# blah blah blaah
abc 1.234
firejail-git 0.9.73.r10.gc66588df8
yt-dlp 2025.03.21
# blah blah blaah
syncthing 1.23.4 # blah blah blah
libvirt 4.2.1 # blah blah
The changes that were made:
The date line was changed (in this case, it should match 2 fields `# date:`
The file was updated to the following accordingly:
I want only the relevant lines changed, with the rest of the file preserving their contents (comment lines and line order).
How to go about this? I had a solution with awk that was pretty close but realized arrays are ordered so couldn't preserve order of the lines. I'm not sure if there's a more efficient way that doesn't running involve running e.g. sed commands (not familiar with sed) on each line which seems to require writing the file for each replacement.
I want comments and line ordering to be preserved. I can't guarantee that the second field must be the version number--it could just be an arbitrary string and in that case I don't want to replace it--only insert the version number as the new second field.
https://redd.it/1juum98
@r_bash
I have a noscript that has the output e.g. (keeping the examples very short):
# date: 2025-04-01T16:31:24-0400
firejail-git 0.9.73.r10.gc66588df8
yt-dlp 2025.03.21
syncthing 1.23.4
libvirt 4.2.1
I want to replace all these lines (comments excluded) with lines in a file whose first field (delimited by space) matches the file's lines' first field and and potentially its second field (if it starts with a number), else add the version number as the second field. Such a file looks like this before replacement:
# date: 2024-04-01T16:31:24-0400
# blah blah blaah
abc 1.234
firejail-git 0.9.72.r10.gc66588df8
yt-dlp
# blah blah blaah
syncthing 1.20.4 # blah blah blah
libvirt
After replacement:
# date: 2025-04-01T16:31:24-0400
# blah blah blaah
abc 1.234
firejail-git 0.9.73.r10.gc66588df8
yt-dlp 2025.03.21
# blah blah blaah
syncthing 1.23.4 # blah blah blah
libvirt 4.2.1 # blah blah
The changes that were made:
The date line was changed (in this case, it should match 2 fields `# date:`
The file was updated to the following accordingly:
firejail-git 0.9.72.r10.gc66588df8, yt-dlp 2025.03.21, syncthing 1.23.4 # blah blah blah (note that the comment is preserved, only the version was updated with field 2 changed), libvirt 4.2.1 # blah blah has the version added as second field)I want only the relevant lines changed, with the rest of the file preserving their contents (comment lines and line order).
How to go about this? I had a solution with awk that was pretty close but realized arrays are ordered so couldn't preserve order of the lines. I'm not sure if there's a more efficient way that doesn't running involve running e.g. sed commands (not familiar with sed) on each line which seems to require writing the file for each replacement.
I want comments and line ordering to be preserved. I can't guarantee that the second field must be the version number--it could just be an arbitrary string and in that case I don't want to replace it--only insert the version number as the new second field.
https://redd.it/1juum98
@r_bash
Reddit
From the bash community on Reddit
Explore this post and more from the bash community