Re: line processing slow
- From: "Janis" <janis_papanagnou@xxxxxxxxxxx>
- Date: 29 Mar 2007 06:14:40 -0700
On 29 Mrz., 14:40, "Terence" <some...@xxxxxxxxxxxxx> wrote:
Hi,
I've a data file with 1million lines. Eg.
aaaaabbbbbbccccddd <- fix column
.......
......
I wanted to insert a comma ','.
This is what i did:
cat $inputfile | while read line
do
field1=`echo $line | cut -c1-5`
field2=`echo $line |cut -c6-11`
field3=`echo $line |cut -c12-15`
echo ${field1},${field2},${field3} >> outputfile
done
for 1million lines, the processing is painful.
Is there any more efficient way of doing the input/output?
Thanks and regards
gawk 'BEGIN{FIELDWIDTHS="5 6 4 3";OFS=","}
{print $1,$2,$3,$4}' "$inputfile" >outputfile
Adjust input column width and fields to be printed to your taste.
Janis
.
- References:
- line processing slow
- From: Terence
- line processing slow
- Prev by Date: Re: Find and list all files containing <string>
- Next by Date: Re: Find and list all files containing <string>
- Previous by thread: Re: line processing slow
- Next by thread: Re: line processing slow
- Index(es):
Relevant Pages
|
|