Cut Paste and Insert Help

Hello

I have a very large file where say each line is made up of 80 characters.
I want to cut the characters from 20-30 and 50-60 from each line and then insert a delimiter between them (# or | etc).
eg
input file
000000000131.12.20990000590425246363375670011200140406
000000000131.12.20990000599116259067695570011200140306
000000000131.12.20990000954757586517205670011200140206
000000000131.12.20990001100136286779157070040749470106
000000000131.12.20990001100331729172935570040774630106
000000000131.12.20990001100417542814864770040736610106
000000000131.12.20990001100565052159608570040771070106

output file
209900005#700112001404
209900005#700112001403
209900009#700112001402
209900011#700407494701
209900011#700407746301
209900011#700407366101
209900011#700407710701

I can cut the relevant characters and put them in 2 files and then using cut paste option make a new file with the desired results. However this will take a long time as the file is huge. Is there a simpler way.
Please help.

Thanks in advance

Regards
Pradeep

first cut the relavent columns and then store in a temp files, then use the paste command to insert the delimiter then at last remove the temp files.

cut -c 20-30 data > t1 ; cut -c 50-54 data > t2 ; paste -d "#" t? ; rm t?

If it is always 20-30 and 50-60, you can use the bash builtin to do what cut does.

Something like

LHS=${line:20:10}
RHS=$(line:50:10}
OUTPUT="${LHS}#${RHS}"

See this post

See man sh for further info.

I request you to pls elaborate on the code given. If my data is present in a file named a1, then how do i use your code to get a file a2 with the desired output. I could not figure out how to use the variables LHS and RHS to extract data from a line in a file.

Regards

sh-2.05b$ cat pradeep.sh 
#! /bin/sh

while read line
do
LHS=${line:16:9}
RHS=${line:40:12}
echo "$LHS#$RHS" >> pradeep
done < pradeep.txt
sh-2.05b$ cat pradeep.txt 
000000000131.12.20990000590425246363375670011200140406
000000000131.12.20990000599116259067695570011200140306
000000000131.12.20990000954757586517205670011200140206
000000000131.12.20990001100136286779157070040749470106
000000000131.12.20990001100331729172935570040774630106
000000000131.12.20990001100417542814864770040736610106
000000000131.12.20990001100565052159608570040771070106
sh-2.05b$ ./pradeep.sh 
sh-2.05b$ cat pradeep
209900005#700112001404
209900005#700112001403
209900009#700112001402
209900011#700407494701
209900011#700407746301
209900011#700407366101
209900011#700407710701
sh-2.05b$ 

Thanks a lot Vino !!!!!!!!
Worked like a charm :slight_smile: