Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cutting spaces where there are none... 1

Status
Not open for further replies.

mwesticle

Programmer
Nov 19, 2003
51
US
I have a file that contains a 10 byte sequence number, followed by a 1 to 3 byte segment id. My file looks like this (without the single quotes):

'1234567890A'
'0987654321BB'
'1111111111CCC'

So, as you see, some records are 11 bytes in width, some are 12, and some are 13.

I want to use "sed", or something like it, to turn every record in this file into a fixed width of 13 bytes, inserting spaces where the data doesn't actually take up the entire 13 bytes. So the data returned will look like this (without the single quotes):

'1234567890A '
'0987654321BB '
'1111111111CCC'

Can anyone help me out here? Thanks once again...
 
The awk way:
Code:
awk '{printf &quot;%-13.13s\n&quot;,$0}'</path/to/file >output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top