[SOLVED] Bash script - use current variable value as number to print a line
by undefineduser from LinuxQuestions.org on (#4VF43)
Hey,
I'm working on a copy script that will copy all files that diff says only appear in the original directory, to the backup directory.
Diff gives me this output, so I have to work a little with the string to get the right target path.
Quote:
My idea was to count the number of lines of the diff file and write it to a variable. Inside the loop I then write the correct path of the current line into a new variable (or array).
If I write awk 'NR==$i' my variable is empty, with 'NR=='$i'' i get an EOF.
Any tips of how I can improve/fix my script?
Code:
Quote:


I'm working on a copy script that will copy all files that diff says only appear in the original directory, to the backup directory.
Diff gives me this output, so I have to work a little with the string to get the right target path.
Quote:
| Only in /usr/share/icons/Adwaita/16x16/apps: user-info1.png Only in /usr/share/icons/Adwaita/48x48/apps: goa-panel-symbolic.symbolic1.png Only in /usr/share/icons/Adwaita/48x48/apps: help-browser-symbolic.symbolic1.png Only in /usr/share/icons/Adwaita/48x48/apps: web-browser1.png |
If I write awk 'NR==$i' my variable is empty, with 'NR=='$i'' i get an EOF.
Any tips of how I can improve/fix my script?
Code:
Quote:
| > #!/usr/bin/env bash > #set -x > > count=$(awk 'END{print NR}' diffoutput.txt) > > for((i="1";i<=$count;++i)) > do >> filename=$(awk 'NR==$i' diffoutput.txt | awk '{print $NF}') >> # ... > done > true |