LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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, 10:13 PM   #1
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Rep: Reputation: 39
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, 10:51 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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-24-2009, 11:08 PM   #3
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Original Poster
Rep: Reputation: 39
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-24-2009, 11:16 PM   #4
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Original Poster
Rep: Reputation: 39
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-24-2009, 11:39 PM   #5
DaveQB
Member
 
Registered: Oct 2003
Location: Sydney, Australia.
Distribution: Debian, Ubuntu
Posts: 400

Original Poster
Rep: Reputation: 39
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 11:27 AM
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 08:55 PM
vsftpd carriage return issue taylorjp75 Linux - Software 1 07-14-2009 06:55 AM
workaround for C++ printf carriage return idc12 Programming 2 09-11-2006 12:13 PM
pppd...carriage return?!? icyfire Linux - Software 1 02-14-2002 07:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:43 AM.

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
Open Source Consulting | Domain Registration