Hi,
I need help with one problem, I came across recently.
I have one input file which I need to delimit based on character length.
$ cat Input.txt
12345sda231453
asd760kjol62569
sdasw4g76gdf57
And, There is one comma separated file which mentions "start of the field" and "length of the field".
$ cat start_length.csv
1,2
3,3
6,3
9,
Expected output is as follows:
12|345|sda|231453
as|d76|0kj|ol62569
sd|asw|4g7|6gdf57
I have used awk to get the expected result as follows:
$ awk 'BEGIN{OFS="|"}{print substr($0,1,2),substr($0,3,3),substr($0,6,3),substr($0,9)}' Input.txt
12|345|sda|231453
as|d76|0kj|ol62569
sd|asw|4g7|6gdf57
But, the problem here is I have hardcoded "start of the field" and "length of the field" in above awk. We have bigger file containing more than 2 lacs record with more than 200 fields. So, It is not possible to hardcode "start of the field" and "length of the field" for each file.
Is there any way in which I can use start_length.csv file and somehow run it in loop to get desired output.