cutting long text by special char around 100 byte and newline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cutting long text by special char around 100 byte and newline
# 1  
Old 12-06-2011
cutting long text by special char around 100 byte and newline

Regard,

How can i cut the text by special char(|) around 100 byte
and write the other of the text at newline using Perl.

2|01|2059140001|34232883774|504106542|2733|2127292||55197897292|||||177011612201|87829918247|2011112 7|0|0|0|295438|251|573|0|0|0|0|0|0|0|0|0|0|0|54630|45890|93609|0|0|0|295330|0|0|||0

Thanks.

Last edited by Shawn, Lee; 12-07-2011 at 12:03 AM..
# 2  
Old 12-06-2011
Try this...
Code:
awk -F'|' '{for(i=1;i<=NF;i++){s+=length($i)+1;if(s<=100){printf $i OFS}else{print $i OFS;s=0}}printf"\n"}' 
OFS='|' input_file

--ahamed

Last edited by ahamed101; 12-07-2011 at 05:12 AM..
This User Gave Thanks to ahamed101 For This Post:
# 3  
Old 12-07-2011
Code:
$ split -b 100 infile ; cat xa*

Then remove the temporarily created files ..
This User Gave Thanks to jayan_jay For This Post:
# 4  
Old 12-07-2011
Code:
# ./justdoit_sp infile
2|01|2059140001|34232883774|504106542|2733|2127292||55197897292|||||177011612201|87829918247|2011112
 7|0|0|0|295438|251|573|0|0|0|0|0|0|0|0|0|0|0|54630|45890|93609|0|0|0|295330|0|0|||0

Code:
 ## code ##
l=100;for((i=1;i<=$(wc -c <$1);i=i+100)) ; do
l=$(($i+$l));cut -c${i}-$l $1 ;done

This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Char/byte positions of delimiters in file

I have a pipe delimited file and I'm trying to write a script that will give the character/byte positions of each pipe in the file. There may be some simple way but I don't know what it is... Can someone help with this? Ex: file has output below abc|def|ghi| I want the script to tell the... (1 Reply)
Discussion started by: basz808
1 Replies

2. Shell Programming and Scripting

Replace Special Character With Next Present Byte

Hi, First find the special character, from the special character take next two bytes convert the bytes to decimal and replace with next present byte of decimal value times. E.g. Input: 302619ú1A? Output: 302619(3 spaces for ú1A)?????????????????????????? Thanks, Dines (27 Replies)
Discussion started by: dineshnak
27 Replies

3. UNIX for Dummies Questions & Answers

Changing a special line and Byte in a random file

Hello I created 3 files by: dd if=/dev/urandom bs=1024 count=1000000 of=./testfile1 dd if=/dev/urandom bs=1024 count=5000000 of=./testfile2 dd if=/dev/urandom bs=1024 count=10000000 of=./testfile3 Now I want to know how to make a change in a specific byte and/or line of theses files? (2 Replies)
Discussion started by: frhling
2 Replies

4. UNIX for Dummies Questions & Answers

Remove newline char from variable

I have a file ABC.DAT with 2 columns avaialble Data format : XYZ!$#$!120 XXZ!$#$!1000 YYZ!$#$!104 While running the following code : FILE_COUNTER=1; RECORD_CN_FILE_COUNT=$((`wc -l ABC.DAT| cut -f1 -d' '`)); while do FILE_NAME=`cat ABC.DAT.DAT| head -$FILE_COUNTER |tail -1 | awk -F... (1 Reply)
Discussion started by: Nikhil Gautam
1 Replies

5. UNIX for Dummies Questions & Answers

Remove a newline char from selected rows.

Greetings! Can we automate the process of removing a newline char from selected rows in a fixed width file using a shell? Input is like abcd1234 xyzd1234 abcd a1b2c3d4 abcd1234 xyzd1234 xx abcd1234 Expected output - abcd1234xyzd1234 abcda1b2c3d4abcd1234xyzd1234 xxabcd1234 ... (2 Replies)
Discussion started by: mailme0205
2 Replies

6. Shell Programming and Scripting

Help substituting text in a file having a single line but no newline char

Hello, Need help substituting a particular word in a file having a single line but no newline character at the end. I was trying to use sed but it doesn't work probably because there is no newline char at the end of the line. $ cat hlq_detail /outputs/alvan23/PDFs/bills $ cat... (5 Replies)
Discussion started by: Shan_u2005
5 Replies

7. Shell Programming and Scripting

Splitting a variable based on newline char

Heeloo all, A weird problem perhaps. May god save others from this problem. I want to print each line from a variable.. the example below should make it clear. smvar="Hello World1 Hello world 2 forgot there I guess" for eachline in $smvar echo $eachline end Whats for... (3 Replies)
Discussion started by: pavanlimo
3 Replies

8. Shell Programming and Scripting

How to replace any char with newline char.

Hi, How to replace any character in a file with a newline character using sed .. Ex: To replace ',' with newline Input: abcd,efgh,ijkl,mnop Output: abcd efgh ijkl mnop Thnx in advance. Regards, Sasidhar (5 Replies)
Discussion started by: mightysam
5 Replies

9. UNIX for Advanced & Expert Users

Using egrep to search for Text and special char

Anyone is well-versed to use egrep to search a file for a line containing both: 1) AAA 2) $ I am having problem escaping the dollar sign when using egrep in conjunction with satisfying AAA as well. E.g. Text file Line 1 AAA Line 2 $$$ Line 3 AAA BBB $ Line 4 $$$ BBB AA will return me... (2 Replies)
Discussion started by: izy100
2 Replies

10. Debian

Serial printer cutting last page of long reports...

Any ideas what could cause this? I have flow control set to XON XOFF on the printer and the on the OS level. (1 Reply)
Discussion started by: djsal
1 Replies
Login or Register to Ask a Question