![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Insert line into file | vinay123 | Shell Programming and Scripting | 3 | 07-01-2008 04:07 AM |
| How to insert new line in the data file using the script | Sona | UNIX for Dummies Questions & Answers | 2 | 08-22-2006 02:17 AM |
| Insert text file at a certain line. | insania | Shell Programming and Scripting | 4 | 08-01-2006 03:46 AM |
| insert a line in a file | RishiPahuja | Shell Programming and Scripting | 7 | 06-22-2005 04:47 AM |
| Insert a line as the first line into a very huge file | shriek | UNIX for Advanced & Expert Users | 3 | 03-09-2005 01:22 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I have a file with over 500 MAC addresses. Each address is on a new line. However, the MACs do not have ":"
I need a script that will read the file, line by line and insert colons in the addresses and then print the results to a new file. current.txt looks like this 111111111111 222222222222 333333333333 Newfile.txt Needs to look like this: 11:11:11:11:11:11 22:22:22:22:22:22 etc.. |
|
||||
|
The reason is because Cygwin behaves like Unix by default, so the output file is created in Unix format (LF terminators instead of CR/LF). Use this to convert it to Windblows format: Code:
sed 's/../&:/g;s/:$//' current.txt | unix2dos > newfile.txt s/../&:/g does a global search and replace for any 2 characters, replacing them by the matched string (&) followed by a ":". This results in 11:11:11:11:11:11:, so the s/:$// part is just to strip off the terminating ":". $ is a special character to match the end of the line. |
![]() |
| Bookmarks |
| Tags |
| editting files scripts |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|