Spliting a line after 255 characters.


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Spliting a line after 255 characters.
# 1  
Old 05-01-2017
Linux Spliting a line after 255 characters.

Hi Guys,
I have a file which contains multiple lines. I need to split each line 255 characters and then I need to add call statement in the front and semi colon at the end.

I/P:
Code:
call sp_rebuildindex('aaa.aaa','column [CUST_ACCT_ID] column [CHANNEL_TYPE_CD1] column [CHANNEL_TYPE_CD2] column [ORD_PRFL_CD] column [MCK_KU_TERM_RSN_CD] column [CUST_STAT_XMPT_CD] column [DLVRY_FEE_CD] column [MCK_KU_DEA_ELIG_CD1] column [MCK_KU_DEA_ELIG_CD2] column [MCK_KU_DEA_ELIG_CD3] column [MCK_KU_DEA_ELIG_CD4] column [MCK_KU_DEA_ELIG_CD5] column [MCK_KU_DEA_ELIG_CD6] column [MCK_KU_DEA_ELIG_CD7] column [MCK_KU_DEA_ELIG_CD8] column [MCK_KU_PVT_LBL_CD] column [ORDR_CONFO_CD] column [POG_OPTN_CD] column [POG_SIGNAGE_CD] column [OTC_RETL_PRC_HIER_CD] column [RX_RETL_PRC_HIER_CD] column [MCK_KU_CONSOL_TYP_CD] column [MCK_KU_MKTG_OPTN_CD]');
call sp_rebuildindex('bbb.bbb','column [CUST_ACCT_ID] column [CHANNEL_TYPE_CD1] column [CHANNEL_TYPE_CD2] column [ORD_PRFL_CD] column [MCK_KU_TERM_RSN_CD] column [CUST_STAT_XMPT_CD] column [DLVRY_FEE_CD] column [MCK_KU_DEA_ELIG_CD1] column [MCK_KU_DEA_ELIG_CD2] column [MCK_KU_DEA_ELIG_CD3] column [MCK_KU_DEA_ELIG_CD4] column [MCK_KU_DEA_ELIG_CD5] column [MCK_KU_DEA_ELIG_CD6] column [MCK_KU_DEA_ELIG_CD7] column [MCK_KU_DEA_ELIG_CD8] column [MCK_KU_PVT_LBL_CD] column [ORDR_CONFO_CD] column [POG_OPTN_CD] column [POG_SIGNAGE_CD] column [OTC_RETL_PRC_HIER_CD] column [RX_RETL_PRC_HIER_CD] column [MCK_KU_CONSOL_TYP_CD] column [MCK_KU_MKTG_OPTN_CD]');

O/P:
Code:
call sp_rebuildindex('aaa.aaa','column [CUST_ACCT_ID] column [CHANNEL_TYPE_CD1] column [CHANNEL_TYPE_CD2] column [ORD_PRFL_CD] column [MCK_KU_TERM_RSN_CD] column [CUST_STAT_XMPT_CD] column [DLVRY_FEE_CD] column [MCK_KU_DEA_ELIG_CD1]');
call sp_rebuildindex('aaa.aaa','column [MCK_KU_DEA_ELIG_CD2] column [MCK_KU_DEA_ELIG_CD3] column [MCK_KU_DEA_ELIG_CD4] column [MCK_KU_DEA_ELIG_CD5] column [MCK_KU_DEA_ELIG_CD6] column [MCK_KU_DEA_ELIG_CD7] column [MCK_KU_DEA_ELIG_CD8]');
call sp_rebuildindex('aaa.aaa','column [MCK_KU_PVT_LBL_CD] column [ORDR_CONFO_CD] column [POG_OPTN_CD] column [POG_SIGNAGE_CD] column [OTC_RETL_PRC_HIER_CD] column [RX_RETL_PRC_HIER_CD] column [MCK_KU_CONSOL_TYP_CD] column [MCK_KU_MKTG_OPTN_CD]');
call sp_rebuildindex('bbb.bbb','column [CUST_ACCT_ID] column [CHANNEL_TYPE_CD1] column [CHANNEL_TYPE_CD2] column [ORD_PRFL_CD] column [MCK_KU_TERM_RSN_CD] column [CUST_STAT_XMPT_CD] column [DLVRY_FEE_CD] column [MCK_KU_DEA_ELIG_CD1]');
call sp_rebuildindex('bbb.bbb','column [MCK_KU_DEA_ELIG_CD2] column [MCK_KU_DEA_ELIG_CD3] column [MCK_KU_DEA_ELIG_CD4] column [MCK_KU_DEA_ELIG_CD5] column [MCK_KU_DEA_ELIG_CD6] column [MCK_KU_DEA_ELIG_CD7] column [MCK_KU_DEA_ELIG_CD8]');
call sp_rebuildindex('bbb.bbb','column [MCK_KU_PVT_LBL_CD] column [ORDR_CONFO_CD] column [POG_OPTN_CD] column [POG_SIGNAGE_CD] column [OTC_RETL_PRC_HIER_CD] column [RX_RETL_PRC_HIER_CD] column [MCK_KU_CONSOL_TYP_CD] column [MCK_KU_MKTG_OPTN_CD]');

Options I tried:

Code:
sed -e "s/.\{255\}/&\n/g" <filename>

If the line end with column then I replaced with ');

I am not sure how to copy the previous copy command. Any help is highly appreciated.

Last edited by Corona688; 05-01-2017 at 02:52 PM..
# 2  
Old 05-01-2017
If none of the columns are text strings, you may be able to use the fold command to split upon spaces:
Code:
fold -w 255 -s < inputfile > outputfile

to avoid splitting in an awkward place.

Last edited by Corona688; 05-01-2017 at 03:39 PM.. Reason: fold, not wrap
# 3  
Old 05-01-2017
I have already tried that option but I need to add "call sp_rebuildindex('<tablename>','column" each line. The table name should be copied from the previous line if the call doesn't exist on that line.
# 4  
Old 05-01-2017
Try
Code:
awk -F, '
        {i = 0
         MX = split ($2, T, "]") - 2
         while (i <= MX)        {OUT = $1 OFS SQ
                                 while ((length (OUT T[i+1]) < 255) && (i <= MX)) OUT = OUT T[++i] "]"
                                 sub (SQ "( |" SQ ")", SQ, OUT)
                                 print  OUT SQ ");"
                                }
        }
' OFS="," SQ="'" file
call sp_rebuildindex('aaa.aaa','column [CUST_ACCT_ID] column [CHANNEL_TYPE_CD1] column [CHANNEL_TYPE_CD2] column [ORD_PRFL_CD] column [MCK_KU_TERM_RSN_CD] column [CUST_STAT_XMPT_CD] column [DLVRY_FEE_CD] column [MCK_KU_DEA_ELIG_CD1]');
call sp_rebuildindex('aaa.aaa','column [MCK_KU_DEA_ELIG_CD2] column [MCK_KU_DEA_ELIG_CD3] column [MCK_KU_DEA_ELIG_CD4] column [MCK_KU_DEA_ELIG_CD5] column [MCK_KU_DEA_ELIG_CD6] column [MCK_KU_DEA_ELIG_CD7] column [MCK_KU_DEA_ELIG_CD8]');
call sp_rebuildindex('aaa.aaa','column [MCK_KU_PVT_LBL_CD] column [ORDR_CONFO_CD] column [POG_OPTN_CD] column [POG_SIGNAGE_CD] column [OTC_RETL_PRC_HIER_CD] column [RX_RETL_PRC_HIER_CD] column [MCK_KU_CONSOL_TYP_CD] column [MCK_KU_MKTG_OPTN_CD]');
call sp_rebuildindex('bbb.bbb','column [CUST_ACCT_ID] column [CHANNEL_TYPE_CD1] column [CHANNEL_TYPE_CD2] column [ORD_PRFL_CD] column [MCK_KU_TERM_RSN_CD] column [CUST_STAT_XMPT_CD] column [DLVRY_FEE_CD] column [MCK_KU_DEA_ELIG_CD1]');
call sp_rebuildindex('bbb.bbb','column [MCK_KU_DEA_ELIG_CD2] column [MCK_KU_DEA_ELIG_CD3] column [MCK_KU_DEA_ELIG_CD4] column [MCK_KU_DEA_ELIG_CD5] column [MCK_KU_DEA_ELIG_CD6] column [MCK_KU_DEA_ELIG_CD7] column [MCK_KU_DEA_ELIG_CD8]');
call sp_rebuildindex('bbb.bbb','column [MCK_KU_PVT_LBL_CD] column [ORDR_CONFO_CD] column [POG_OPTN_CD] column [POG_SIGNAGE_CD] column [OTC_RETL_PRC_HIER_CD] column [RX_RETL_PRC_HIER_CD] column [MCK_KU_CONSOL_TYP_CD] column [MCK_KU_MKTG_OPTN_CD]');

This User Gave Thanks to RudiC For This Post:
# 5  
Old 05-01-2017
Thanks for your help and It worked fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove first 2 characters and last two characters of each line

here's what im trying to do. i have a file containing lines similar to this: data.txt: 1hsRmRsbHRiSFZNTTA1dlEyMWFkbU5wUW5CSlIyeDFTVU5SYjJOSFRuWmpia0ZuWXpKV2FHTnRU 1lKUnpWMldrZFZaMG95V25oYQpSelEyWTBka2QyRklhSHBrUjA1b1kwUkJkd3BOVXpWM1lVaG5k... (5 Replies)
Discussion started by: SkySmart
5 Replies

2. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

3. Shell Programming and Scripting

[Solved] How to separate one line to mutiple line based on certain number of characters?

hi Gurus, I need separate a file which is one huge line to multiple lines based on certain number of charactors. for example: abcdefghi high abaddffdd I want to separate the line to multiple lines for every 4 charactors. the result should be abcd efgh i hi gh a badd ffdd Thanks in... (5 Replies)
Discussion started by: ken6503
5 Replies

4. UNIX for Dummies Questions & Answers

How to specify beginning-of-line/end-of-line characters inside a regex range

How can I specify special meaning characters like ^ or $ inside a regex range. e.g Suppose I want to search for a string that either starts with '|' character or begins with start-of-line character. I tried the following but it does not work: sed 's/\(\)/<do something here>/g' file1 ... (3 Replies)
Discussion started by: jawsnnn
3 Replies

5. Shell Programming and Scripting

Ignore the 255 character limit of command line

Hi I would just like to ask if there is a way for UNIX to ignore/overcome the 255 character limit of the command line? My problem is that I have a really long line of text from a file (300+ bytes) which i have to "echo" and process by adding commands like "sed" to the end of the line, like... (5 Replies)
Discussion started by: agentgrecko
5 Replies

6. Shell Programming and Scripting

echo !SR | nc 255.255.2.2 80 - how to in XP?

Hi guys I am trying to interface with an old industrial scanner through an old PC with an old network card and a copy of Linux. It now needs to speak to a Windows XP machine, but I have no idea what the Windows equivalent of these functions would are: echo !1 | nc 255.255.2.2 80 echo ?2 | nc... (3 Replies)
Discussion started by: TonyG
3 Replies

7. Shell Programming and Scripting

Get the 1st 99 characters and add new line feed at the end of the line

I have a file with varying record length in it. I need to reformat this file so that each line will have a length of 100 characters (99 characters + the line feed). AU * A01 EXPENSE 6990370000 CWF SUBC TRAVEL & MISC MY * A02 RESALE 6990788000 Y... (3 Replies)
Discussion started by: udelalv
3 Replies

8. Shell Programming and Scripting

sed limitation of 255 characters

Gurus, sed -e "s/\(.\{1,255\}\)\(.\{1,2\}\)\(.*\)/\1AB\3/" FILE ---this works sed -e "s/\(.\{1,468\}\)\(.\{1,2\}\)\(.*\)/\1AB\3/" FILE ---this does not It works only till 1,255 ( any number below 255 works) Any one know how to increase this limit. Thanks Sirababu (4 Replies)
Discussion started by: sirababu
4 Replies

9. Shell Programming and Scripting

Deleting Characters at specific position in a line if the line is certain length

I've got a file that would have lines similar to: 12345678 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 23456781 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 34567812 x.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 45678123 x.00 xx.00 xx.00 xx.00 xx.00 x.00 xxx.00 xx.00 xx.00 xx.00 xx.00... (10 Replies)
Discussion started by: Cailet
10 Replies

10. Shell Programming and Scripting

Spliting the line based on position.

i want to split a big line based on the position. example : I have a single line which has 2300 characters. i want to split from 1 character to 300th characters as first line and 301th to 600 as second line and 601th to 900 as third line ...till the end of the string. Can anyone help... (1 Reply)
Discussion started by: senthil_is
1 Replies
Login or Register to Ask a Question