Results 1 to 10 of 18
I'm having problems with the newline character on the end of a variable.
The variable is storing an ip address assigned like this:
... | awk '{print $NF}' | uniq ...
- 12-20-2007 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 10
Scripting, removing newline
I'm having problems with the newline character on the end of a variable.
The variable is storing an ip address assigned like this:
... | awk '{print $NF}' | uniq | while read LINE
when I attempt to look up information with host I get this:
host $LINE
Which returns - Host 190.126.210.135\013 not found: 3(NXDOMAIN)
I'm been playing with awk and sed to get rid of the newline but I've had no luck and would welcome some help.
Thanks
- 12-20-2007 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
show the whole thing
- 12-20-2007 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 10
input=../files/data*
tac $input | grep "string" | awk '{print $NF}' | uniq | while read LINE
do
host $LINE
done
- 12-20-2007 #4
That's not a newline you're struggling with. The newline has already been removed for you. You seem to have a CR before the LF.
Try this:
For more information, do this at the command line:Code:tac $input | fromdos | grep "string" | awk '{print $NF}' | uniq | while read LINE do host $LINE done
Hope this helps.Code:man fromdos
--
Bill
Old age and treachery will overcome youth and skill.
- 12-20-2007 #5Just Joined!
- Join Date
- Dec 2007
- Posts
- 10
Sorry I should have said I'm using Bash, it doesn't appear to support that command.
- 12-20-2007 #6Just Joined!
- Join Date
- Nov 2004
- Posts
- 18
you can try
Code:tac $input | grep "string" | awk '{print $NF}' | uniq | tr -d '\v' | while read LINE do host "$LINE" done
- 12-20-2007 #7Just Joined!
- Join Date
- Dec 2007
- Posts
- 10
That hasn't worked, output is the same.
- 12-20-2007 #8Just Joined!
- Join Date
- Nov 2004
- Posts
- 18
well, the next thing would be:
Code:tac $input | grep "string" | awk '{print $NF}' | uniq | tr -d '\013' | while read LINE do host "$LINE" done
- 12-20-2007 #9Just Joined!
- Join Date
- Dec 2007
- Posts
- 10
I did try that as well, no luck.
- 12-20-2007 #10Just Joined!
- Join Date
- Nov 2004
- Posts
- 18
How about:
Code:for h in "$(tac $input | grep "string" | awk '{print $NF}' | uniq)"; do host "$h" done


Reply With Quote