Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux:bash [2022/09/21 01:53] – [Linux move files] admin | linux:bash [2024/02/14 06:45] (current) – [Linux.Bash] admin | ||
---|---|---|---|
Line 8: | Line 8: | ||
setopt histreduceblanks | setopt histreduceblanks | ||
+ | </ | ||
+ | |||
+ | <code BASH> | ||
+ | # check xterm color | ||
+ | msgcat | ||
+ | </ | ||
+ | ++++ Пример| | ||
+ | {{: | ||
+ | ++++ | ||
+ | <code BASH> | ||
+ | # grep for configuration without comment line | ||
+ | egrep -v " | ||
</ | </ | ||
bash | bash | ||
Line 64: | Line 76: | ||
# transform input from {type: a, amount: 1} to {a: 1} and sum all values by type | # transform input from {type: a, amount: 1} to {a: 1} and sum all values by type | ||
jq '[ .[] | {(.type): .amount} ] | map(to_entries) | add | group_by(.key) | map({key: .[0].key, value: map(.value) | add}) | from_entries' | jq '[ .[] | {(.type): .amount} ] | map(to_entries) | add | group_by(.key) | map({key: .[0].key, value: map(.value) | add}) | from_entries' | ||
+ | # invert selection of contains key name | ||
+ | journalctl -f -o json | jq -cr ' | ||
+ | </ | ||
+ | |||
+ | image magic | ||
+ | <code BASH> | ||
+ | create collage from files | ||
+ | " | ||
</ | </ | ||
Line 129: | Line 149: | ||
===== Scripting ===== | ===== Scripting ===== | ||
* scripting pitfails https:// | * scripting pitfails https:// | ||
+ | |||
+ | |||
+ | ===== Scripting-code ===== | ||
+ | * read line by line - https:// | ||
+ | |||
+ | <code BASH> | ||
+ | |||
+ | #!/bin/bash | ||
+ | |||
+ | # Declare variables | ||
+ | vm_name="" | ||
+ | vm_path="" | ||
+ | skipped_lines="" | ||
+ | current_line_number=1 | ||
+ | |||
+ | # Read the file line by line | ||
+ | while IFS=';' | ||
+ | # Check if the line has the correct format | ||
+ | if [[ -z " | ||
+ | skipped_lines=" | ||
+ | fi | ||
+ | |||
+ | # Process the variables here if the line has the correct format | ||
+ | if [[ -n " | ||
+ | echo "VM name: $vm_name" | ||
+ | echo "VM path: $vm_path" | ||
+ | fi | ||
+ | |||
+ | # Increment the line number | ||
+ | current_line_number=$((current_line_number+1)) | ||
+ | done < file.txt | ||
+ | |||
+ | # Print the skipped lines | ||
+ | if [[ -n " | ||
+ | echo "The following lines were skipped because they did not have the correct format:" | ||
+ | echo " | ||
+ | fi | ||
+ | </ |