[Solved] Backup bash script explain

[ad_1] This Bash script will: Set the source directory (SOURCE). Set the destination backup directory (BACKUP). Set the destination directory for latest full backup (LBACKUP). Get the current system date in Y-m-d-Time format (DATE). Sets the destination directory as BACKUP+/+DATE+-diff. Rsync/copy the files from the SOURCE to the DESTINATION folder by comparing the files from … Read more

[Solved] Practice Linux Shell Scripting

[ad_1] Consider adding a counter, bump it up on every line, and print the counter with every line. Also note fixes to set log_file, update to read command. log_file=”/home/user/log.txt” line_no=0 while read -r line do line_no=$((line_no+1)) printf “%d. %s\n” $line_no “$line” done < “$log_file” One alternative to consider is to call the nl utility, which … Read more

[Solved] How to create a flag with getopts to run a command

[ad_1] Your script has a number of problems. Here is the minimal list of fixes to get it working: While is not a bash control statement, it’s while. Case is important. Whitespace is important: if [“$CHECKMOUNT”= “true”] doesn’t work and should cause error messages. You need spaces around the brackets and around the =, like … Read more

[Solved] file validation in linux scripting

[ad_1] If you want to do it in pure bash, use the following script: #!/bin/bash while read line; do line=( ${line//[:]/ } ) for i in “${!line[@]}”; do [ ! -z “${line[$i]##*[!0-9]*}” ] && printf “integer” || printf “string” [ “$i” -ne $(( ${#line[@]} – 1)) ] && printf “:” || echo done done < … Read more

[Solved] How to process this text [closed]

[ad_1] You could simply do this through awk, $ awk -F[,-] ‘{var=$1″-“$2; for (i=3;i<=NF;i++){print var”-“$i}}’ file 86-22-63385835 86-22-63385836 86-22-63385933 86-0577-88609993 86-0577-88835386 86-21-58947602 86-21-58947603 0086-755-33186858 0086-755-33186862 0086-755-33186859 2 [ad_2] solved How to process this text [closed]

[Solved] How to get the specific data in a file and direct its output to to new file?

[ad_1] The following awk script should solve your probelm provided you manually add the School heading yourself or if that remains same add it as BEGIN { printf “School” } in below example. $ cat input_file Mark,Texas High, Dallas, k-5 Steve,SA high,Antonio,k-5 Adam,Plano tech,k-5 $ awk -F, ‘BEGIN { sep = “”} { printf(“%s%s”, sep, … Read more

[Solved] How to cut image into pieces, randomize them and put all together

[ad_1] You can do it like this with bash and ImageMagick: #!/bin/bash convert -crop 16×16@ input.jpg tile.jpg montage -geometry +0+0 $(ls tile*jpg | awk ‘BEGIN{srand()}{print rand() “\t” $0}’ | sort -n | cut -f2-) output.png # Remember to remove the tile*jpg before you do another one 🙂 # rm tile*jpg Basically as you suggest, using … Read more

[Solved] looping over AWK commands doesn’t work [duplicate]

[ad_1] Because your awk program is in single quotes, there will not be any shell variable expansion. In this example: awk ‘tolower($0)~/^alphabet/{print}’ titles-sorted.txt > titles-links/^alphabet.txt …you are looking for the lines that begin with the literal string alphabet. This would work: awk “tolower(\$0)~/^$alphabet/{print}” titles-sorted.txt > titles-links/$alphabet.txt Note several points: We are using double quotes, which … Read more