Visit Our UNIX and Linux User Community


Need to split record


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to split record
# 8  
Old 08-20-2013
Code:
$ echo "breakAfterThreeChars:" | perl -ne  's/(\w{3,3})/\1\n/g;print'
bre
akA
fte
rTh
ree
Cha
rs:

This User Gave Thanks to rajamadhavan For This Post:
# 9  
Old 08-20-2013
Quote:
Req: one record should be split into multiple
For me, this i/p: 123456789 is one record, and two fields.
# 10  
Old 08-20-2013
Hi.
Code:
$ echo 123456789 | fold -w 3
123
456
789

Best wishes ... cheers, drl
These 2 Users Gave Thanks to drl For This Post:
# 11  
Old 08-20-2013
HemaV,
Check this out.. using awk:

Code:
$ awk '{a=length($0);for(i=1;i<=a;i=i+3) print substr($0,i,3)}' file
123
456
789

Enjoy..
# 12  
Old 08-21-2013
Quote:
Originally Posted by Jotne
For me, this i/p: 123456789 is one record, and two fields.
I believe that the point he was trying to make (and what everyone else seems to have assumed) is that i/p: and o/p: are not part of the actual data, but only labels in the forum post's text to refer to the input data and the output data.

Regards,
Alister
# 13  
Old 08-21-2013
Aha, I did not think of that.
# 14  
Old 08-21-2013
Quote:
Originally Posted by rdcwayx
Code:
echo 123456789 |sed 's/\(...\)/\1\n/g'

When the original post does not specify a platform, it would be thoughtful to avoid using proprietary extensions that provide zero benefit and have a portable counterpart.

Aside from the potentially problematic \n, the explicit capture and backreference aren't needed.
Code:
sed 's/.../&\
/g'

Note that both variations of this approach will insert additional blank lines after each line that is a multiple of 3 characters long.

In my opinion, however, anything other than fold is just an academic exercise.

Regards,
Alister

Previous Thread | Next Thread
Test Your Knowledge in Computers #4
Difficulty: Medium
The UNIX and Linux Forums was one of the first forums on the Internet to have a strong moderation policy to encourage users of all skill levels to participate without fear of being bullied.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to split large file with different record delimiter?

Hi, I have received a file which is 20 GB. We would like to split the file into 4 equal parts and process it to avoid memory issues. If the record delimiter is unix new line, I could use split command either with option l or b. The problem is that the line terminator is |##| How to use... (5 Replies)
Discussion started by: Ravi.K
5 Replies

2. Shell Programming and Scripting

How to split one record to multiple records?

Hi, I have one tab delimited file which is having multiple store_ids in first column seprated by pipe.I want to split the file on the basis of store_id(separating 1st record in to 2 records ). I tried some more options like below with using split,awk etc ,But not able to get proper output. can... (1 Reply)
Discussion started by: jaggy
1 Replies

3. UNIX for Dummies Questions & Answers

Split single record to multiple records

Hi Friends, source .... col1,col2,col3 a,b,1;2;3 here colom delimeter is comma(,). here we dont know what is the max length of col3 means now we have 1;2;3 next time i will receive 1;2;3;4;5;etc... required output .............. col1,col2,col3 a,b,1 a,b,2 a,b,3 please give me... (5 Replies)
Discussion started by: bab.galary
5 Replies

4. Shell Programming and Scripting

split content and write to new record

Hi, Help required to split record value and write to new row. Input a~b~c~value in ('3','4','5')~test output a~b~c~3~test a~b~c~4~test a~b~c~5~test input a~b~c~value in ('3','4')~test output a~b~c~3~test a~b~c~4~test (8 Replies)
Discussion started by: Jairaj
8 Replies

5. UNIX for Dummies Questions & Answers

split record without pattern

Hi , I have file with all records in one line, which needs to split it to have a fixed length.Am trying to execute the below script for the same FILENAME="$1" while line LINE do echo $LINE | awk 'BEGIN{n=1}{while(substr($0,n,10)){print substr($0,n,10);n+=10}}' done < $FILENAME it... (4 Replies)
Discussion started by: nishantrk
4 Replies

6. Shell Programming and Scripting

split record based on delimiter

Hi, My inputfile contains field separaer is ^. 12^inms^ 13^fakdks^ssk^s3 23^avsd^ 13^fakdks^ssk^a4 I wanted to print only 2 delimiter occurence i.e 12^inms^ 23^avsd^ (4 Replies)
Discussion started by: Jairaj
4 Replies

7. Shell Programming and Scripting

Record split.

I want to keep only records contain length is 10 other records should remove from my original file without redirecting to other output file. Source 1234567890 123456789011234 abcdefghil Expected Result 1234567890 abcdefghil (9 Replies)
Discussion started by: Jairaj
9 Replies

8. Shell Programming and Scripting

Split a record based on particular match

Hi , I have a requirement to split the record based on particular match using UNIX. Case1: Input Record : 10.44.48.63;"Personals/Dating;sports";1441 Output Records : 10.44.48.63;Personals/Dating;1441;Original 10.44.48.63;sports;1441;Dummy Case2: Input Record : ... (5 Replies)
Discussion started by: mksuneel
5 Replies

9. Shell Programming and Scripting

How to split a file record

-Hi, I have a problem with parcing/spliting a file record into two parts and assigning the split parts to two viriables. The record is as follows: ftrn facc ttrd feed xref fsdb fcp ruldb csdb omom fordr ftxn fodb fsdc texc oxox reng ttrn ttxn fqdb ... (5 Replies)
Discussion started by: aoussenko
5 Replies

10. Shell Programming and Scripting

Split a record

UNIX Scripting Hi I am trying to read a record and split it into multiple records My Record looks like this 1001A0010@B0010*&^0)C0012hgdj&6sD0020fhfri93kivmepi9 where UniqueID is 1001 segments are A,B,C,D length of each segment is 4 characters after the segment 0010 for A 0010 for B 0012... (5 Replies)
Discussion started by: pukars4u
5 Replies

Featured Tech Videos