[Solved] Backup bash script explain

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 LBACKUP … Read more

[Solved] Practice Linux Shell Scripting

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 performs … Read more

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

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 so: … Read more

[Solved] file validation in linux scripting

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 < $1 … Read more

[Solved] How to process this text [closed]

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 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?

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, $2); … Read more

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

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 -crop … Read more

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

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 does … Read more