Solved Want to include blank space.

May 17, 2011 at 07:14:19
Specs: Windows XP
Hi,
I have a Text file. some records ends with 316byte length and some with 315. I want each to be end with 320 length. I just want to add space in end of each record.
IF a record ends with 315 then include 5spaces
IF a record ends with 316 then include 4spaces
Please help in this
thanks,
Umar

See More: Want to include blank space.

Report •

#1
May 17, 2011 at 12:11:11
http://www.unix.com/shell-programmi...

There is one of many sites when I searched google for
add blank space using sed.

How do you know when a politician is lying? His mouth is moving.


Report •

#2
May 17, 2011 at 12:24:25
✔ Best Answer
Another way is to use the printf field length specifier which awk supports:

awk '{ printf("%-320s\n", $0) }' data.txt > newdata.txt


Report •

#3
May 18, 2011 at 01:03:13
@nails
Thanks
It is working. But,

consider there 10 lines in a file.
eg:

HJUNCAL 738 5 A 1062
HBARRIO CASTORES 296 1670
HJUAN A SARACHAGA 3161 1712
HGRAL ARREDONDO 4345 1874
HINDEPENDENC 875 1653
HACASSUSO 2559 1636
HPLAZA ESPAùA 57 1 B 1900
HVTE. LOPEZ Y PLANES 568 1636
HAV DE LA RECONQUISTA 464 8000
HDON BOSCO 3161 18 1642
HGRAL LAS HERAS 147 3 B 1842
HAV LISANDRO DE LA TORRE 1506
HARENALES 1522 10 A 1061
HARENALES 1522 10 A 1061.
In the 7th line there is special character. since it is present, the process getting stopped at "HPLAZA ESPA" and rested of the records are not getting executed.i am not getting the complete file.

Thanks
Umar


Report •

Related Solutions

#4
May 18, 2011 at 05:21:58
Thanks
It is working. But,
consider there 10 lines in a file.
eg:
HJUNCAL 738 5 A 1062
HBARRIO CASTORES 296 1670
HJUAN A SARACHAGA 3161 1712
HGRAL ARREDONDO 4345 1874
HINDEPENDENC 875 1653
HACASSUSO 2559 1636
HPLAZA ESPAùA 57 1 B 1900
HVTE. LOPEZ Y PLANES 568 1636
HAV DE LA RECONQUISTA 464 8000
HDON BOSCO 3161 18 1642
HGRAL LAS HERAS 147 3 B 1842
HAV LISANDRO DE LA TORRE 1506
HARENALES 1522 10 A 1061
HARENALES 1522 10 A 1061.
In the 7th line there is special character. since it is present, the process getting stopped at "HPLAZA ESPA" and rested of the records are not getting executed.i am not getting the complete file.
Thanks
Umar

Report •

#5
May 18, 2011 at 09:18:10
The basic Unix tool set is designed to work on ASCII/text files. The special characters inserted in the file make that file no longer a text file, and how unix tools react will vary between different *nix variants.

I pasted your text into a file on my Solaris 9 box, and the awk script appears to work. What version of Unix are you using?

I don't mean to elaborate on the obvious, but I think you are going to have to remove the special characters. You can probably do that in vi if there are not too many.


Report •

Ask Question