LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux > 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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 09-24-2009, 11:13 PM   #1
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Mandriva 2009.1, Debian Etch
Posts: 344
Thanked: 7
Cut adding $ and carriage return characters for MAC addresses


[Log in to get rid of this advertisement]
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
linux DaveQB is offline  
Tag This Post , ,
Reply With Quote
Old 09-24-2009, 11:51 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 5.4
Posts: 7,428
Thanked: 325
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.
windows_xp_2003 chrism01 is online now     Reply With Quote
Old 09-25-2009, 12:08 AM   #3
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Mandriva 2009.1, Debian Etch
Posts: 344
Thanked: 7

Original Poster
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]?
linux DaveQB is offline     Reply With Quote
Old 09-25-2009, 12:16 AM   #4
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Mandriva 2009.1, Debian Etch
Posts: 344
Thanked: 7

Original Poster
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
linux DaveQB is offline     Reply With Quote
Old 09-25-2009, 12:39 AM   #5
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Mandriva 2009.1, Debian Etch
Posts: 344
Thanked: 7

Original Poster
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.
linux DaveQB is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
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
Minicom carriage return + hyperterminal kewl Linux - Software 1 07-09-2009 07:14 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 07:22 PM.

Main Menu
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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration