In addition to what RudiC and Scrutinizer have already said, why would you write a 28 line Korn shell function using a pipeline of echo and awk to get at awk's printf function when ksh's built-in printf utility can do the same thing in 5 lines?
Note that the leading space on the 1st line of your script makes that line just a comment and removes its ability to specify that your script is to be run by /bin/ksh.
And, note that calling this function fixed_output_format is a misnomer if the arguments you supply to this function contain strings that are longer than the specified field widths. If you really want fixed width output for each field (truncating long input strings), you would want to change:
to:
To see what difference this makes, add an additional line to the end of your script:
and look at the last two lines printed into OUTPUT_FILE by the above printf statement suggestions.
With your current format you'd get:
and with the alternative you'd get:
This User Gave Thanks to Don Cragun For This Post:
hi thanks a lot
But pls help me if my input file is the below format:
Name priya 2010-09-21 10:43:49
TEXT ID 1
hi
TEXT ID 2
how
TEXT ID 3
r
TEXT ID 4
u
Name2 priya2 2010-09-21 10:43:49
TEXT ID 1
hi1
TEXT ID 2
how1
TEXT ID 3
r1 (4 Replies)
Pls help in formatting a txt file using shell scripting
Input file format:
Name priya 2010-09-21 10:43:49
TEXT ID 1
hi
TEXT ID 2
how
TEXT ID 3
r
TEXT ID 4
u
Output required:
name priya hi how r u (4 Replies)
I am new ot unix. Is there one or two lines of command (sed may be) to format a file.
My source is..
<tag1>
<tag2>
<datatag1>
data1
</datatag1>
<datatag2>
data2
</datatag2>
<datatag3>
data3
</datatag3>
<datatag4>
data1
</datatag3>
</tag2>
</tag1> (2 Replies)
I have a file called vm.cfg .
content of file.
acpi = 1
apic = 1
builder = 'hvm'
How would i write a script which will add
boot = 'd' at 3rd line.
For example.
after running the script the file should be like below.
acpi = 1
apic = 1
boot = 'd'
builder = 'hvm'
I dont want to... (3 Replies)
Hi,
I am new to unix , I have a requirement for formating the input file and generate the output file as per the downstream requirement ..
My application receiving a text input file having 4 field and my application need to check each field and if some value of a field is blank ..then it need... (1 Reply)
Hi,
I have a file with only data 1 row:
AA#?BB#?CC#?DD
Assume '#?' is the delimiter, i want the output in another file to be:
AA
BB
CC
DD
Pls let me know if this is possible by sed ?
Thanks in advance. (3 Replies)
I have two files file1 and file2 as shown below:
file1:
name
nameabc
bcd
nameabcdefg
file2:
age
age1111
age2345
age6743
I have pasted one file on the other with the delimiter "|" and the resulttant file is:
name|age
nameabc|age1111
bcd|age2345
nameabcdefg|age6743 (1 Reply)