Article 4VF43 [SOLVED] Bash script - use current variable value as number to print a line

[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:
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
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:
> #!/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
latest?d=yIl2AUoC8zA latest?i=w64iuVwtYtQ:jdHmBja14UI:F7zBnMy latest?i=w64iuVwtYtQ:jdHmBja14UI:V_sGLiP latest?d=qj6IDK7rITs latest?i=w64iuVwtYtQ:jdHmBja14UI:gIN9vFww64iuVwtYtQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments