Reputation: 349
I'm making a script to preform "dig ns google.com" and cut off the all of the result except for the answers section.
So far I have:
#!/bin/bash
echo -n "Please enter the domain: "
read d
echo "You entered: $d"
dr="$(dig ns $d)"
sr="$(sed -i 1,10d $dr)"
tr="$(head -n -6 $sr)"
echo "$tr"
Theoretically, this should work. The sed and head commands work individually outside of the script to cut off the first 10 and last 6 respectively, but when I put them inside my script sed comes back with an error and it looks like it's trying to read the variable as part of the command rather than the input. The error is:
sed: invalid option -- '>'
So far I haven't been able to find a way for it to read the variable as input. I've tried surrounding it in "" and '' but that doesn't work. I'm new to this whole bash scripting thing obviously, any help would be great!
Upvotes: 1
Views: 302
Reputation: 67497
you're assigning the lines to variables, instead pipe them for example
seq 25 | tail -n +11 | head -n -6
will remove the first 10 and last 6 lines and print from 11 to 19. in your case replace seq 25 with your script
dig ns "$d" | tail -n +11 | head -n -6
no need for echo either.
Upvotes: 1