LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 09-24-2009, 11:13 PM   #1
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: PCLinuxOS 2010.12, Debian Lenny
Posts: 387

Rep: Reputation: 38
Cut adding $ and carriage return characters for MAC addresses


I have go a different way with this script, but very curious about this.


First the script I am using
Code:
cat mac.sh
#!/bin/bash -x


ifconfig eth0| grep HWaddr |tr -s ' ' |cut -d' ' -f5
MAC=`ifconfig eth0| grep HWaddr |tr -s ' ' |cut -d' ' -f5`

grep "$MAC"  maclist.txt|tr -s " " |cut -d" " -f1
HO1=`grep "$MAC"  maclist.txt |tr -s " " |cut -d" " -f1`
printf ${HO1}

grep "$MAC"  maclist.txt |tr -s " " |cut -d" " -f2
HO2=`grep "$MAC"  maclist.txt |tr -s " " |cut -d" " -f2`
printf ${HO2}

A='00:23:AE:69:C0:F2'
printf  ${A}

exit 0

And the output:

Code:
./mac.sh
+ ifconfig eth0
+ grep HWaddr
+ tr -s ' '
+ cut '-d ' -f5
00:23:AE:69:C0:F2
++ ifconfig eth0
++ grep HWaddr
++ tr -s ' '
++ cut '-d ' -f5
+ MAC=00:23:AE:69:C0:F2
+ grep 00:23:AE:69:C0:F2 maclist.txt
+ tr -s ' '
+ cut '-d ' -f1
om012274
++ grep 00:23:AE:69:C0:F2 maclist.txt
++ tr -s ' '
++ cut '-d ' -f1
+ HO1=om012274
+ printf om012274
om012274+ grep 00:23:AE:69:C0:F2 maclist.txt
+ tr -s ' '
+ cut '-d ' -f2
00:23:AE:69:C0:F2
++ grep 00:23:AE:69:C0:F2 maclist.txt
++ tr -s ' '
++ cut '-d ' -f2
+ HO2=$'00:23:AE:69:C0:F2\r'
+ printf $'00:23:AE:69:C0:F2\r'
+ A=00:23:AE:69:C0:F2
+ printf 00:23:AE:69:C0:F2
00:23:AE:69:C0:F2+ exit 0

The bit I am curious about is:
+ HO2=$'00:23:AE:69:C0:F2\r'

Anyone handy with text processing know about this?

Thanks
 
Old 09-24-2009, 11:51 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
How did you create maclist.txt, on MSWin?
If so, you need to run dos2unix over it first to cvt MS line endings to Linux ones.
 
Old 09-25-2009, 12:08 AM   #3
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: PCLinuxOS 2010.12, Debian Lenny
Posts: 387

Original Poster
Rep: Reputation: 38
chrism01 oh of course. So obvious now.
Our Windows guy here created it, so that explains the carriage return.

But what about the prepended $ ?

Its like a regex start of line, but why would cut add that [or grep]?
 
Old 09-25-2009, 12:16 AM   #4
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: PCLinuxOS 2010.12, Debian Lenny
Posts: 387

Original Poster
Rep: Reputation: 38
It might be tr that's adding or such.


Code:
+ grep 00:23:AE:69:C0:F2 /mnt/altiris/maclist.txt
+ tr -s ' '
om012274 00:23:AE:69:C0:F2
++ grep 00:23:AE:69:C0:F2 /mnt/altiris/maclist.txt
++ tr -s ' '
' HO2='om012274 00:23:AE:69:C0:F2
+ printf om012274 $'00:23:AE:69:C0:F2\r'
om012274+ grep 00:23:AE:69:C0:F2 /mnt/altiris/maclist.txt
+ tr -s ' '
+ cut '-d ' -f2
00:23:AE:69:C0:F2
++ grep 00:23:AE:69:C0:F2 /mnt/altiris/maclist.txt
++ tr -s ' '
++ cut '-d ' -f2
+ HO2=$'00:23:AE:69:C0:F2\r'
+ printf $'00:23:AE:69:C0:F2\r'
+ A=00:23:AE:69:C0:F2
 
Old 09-25-2009, 12:39 AM   #5
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: PCLinuxOS 2010.12, Debian Lenny
Posts: 387

Original Poster
Rep: Reputation: 38
So I converted the line endings with vi and now the $ is gone too.

So for some reason DOS line endings added $ at the beginning of the MAC address but not the hostname which is at the start of the line.

Weird.
 
  


Reply

Tags
cut, mac


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Minicom carriage return + hyperterminal kewl Linux - Software 2 03-22-2010 12:27 PM
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 09:55 PM
vsftpd carriage return issue taylorjp75 Linux - Software 1 07-14-2009 07:55 AM
workaround for C++ printf carriage return idc12 Programming 2 09-11-2006 01:13 PM
pppd...carriage return?!? icyfire Linux - Software 1 02-14-2002 08:07 AM


All times are GMT -5. The time now is 02:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration