although now that i think about it, it would have been easier to let the code above that backslashes everything to also backslash space characters. \\1 = capture group 1 - which does not include the leading hash (#) and does not include leading whitespace - in this case capture group 1 is being used to set the name of the name/value pair in the bash associative array.A1\\[ - literal characters A1[ to start array assignment in an array called A1.the (replace) pattern puts an equals sign between capture group 1 and capture group 2Ĭapture the rest of the line as capture group 2.it's not part of any capture group, and because.that will be replaced with an equals sign because.require a space (or tab, or whitespace).capture the first word as caputure group 1 (\\1).require but ignore leading comment characters (#).\\S - exactly one NON-whitespace character.\\s - one or more whitespace characters.\\S - one or more NON-whitespace characters.\\s* - zero or more whitespace characters.In english: replace each line with a pound symbol followed by the line that was replaced Convert User Value to A1="value" sed -i -E "s/^#\\s*(\\S )\\s (\\S.*?)\\s*\$/A1\\=\"\\2\"/" ~/. In english: capture each line as caputure group 1 (\\1) I don't want to accidentally execute arbitrary code. I do this because later I intend to execute ~/. using the source command and because I don't know for sure the whole format of File_1.txt. In english: if more than one match is found on the same line, replace them all Comment Out the Entire Script sed -i -E "s/^(.*)$/#\\1/" ~/.Ībove uses a regular expression to prefix every line of ~/. with a bash comment character ( #). In english: prefix all special characters with a backslash In english: capture any punctuation or special character as caputure group 1 (\\1) = match any character that is NOT a letter, digit or space.= match any character NOT in a specific list of characters.= match a character from a specific list of characters.The script pattern "s/(find)/(replace)/" specifically performs the pattern match. Sed can do a lot more than regular expression pattern matching. I don't know what other characters might have special meaning, but I want to escape them all with a backslash: sed -i -E "s/()/\\\\\\1/g" ~/. What I don't know is how much I don't know about bash. $() - idk what this does but i think it can execute code.Requires bash v4 for associative arrays. Writes the name to Output_file if changed. To print to the terminal window: /path/to/compare.py Ĭompares name/value pairs in 2 files in the format name value\n. With a few extra lines, you can make it either print to an outputfile, or to the terminal, depending on if the outputfile is defined: Mismatch = for item in data1 if not item in data2] Return ĭata1 = readfile(file1) data2 = readfile(file2) Litteraly sticking to the question (file1, file2, outputfile with "has changed" message) the script below works.Ĭopy the script into an empty file, save it as compare.py, make it executable, run it by the command: /path/to/compare.py įile1 = sys.argv file2 = sys.argv outfile = sys.argv
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |