How to split a text after fix character count


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to split a text after fix character count
# 1  
Old 10-22-2008
How to split a text after fix character count

HI,

I want to split a text after certain fix character count in text.

For eg: My file is containing text like:

AURBJR,AURCID,AURVID,CHANDV,DAMNEW,DHMMAN,GANGAN,GARKHE,GOREGA,JEJKHA,JEJSHI,JINTUR,JMKKUS,JUNAWA,KA LKAL,KHOJEW,KUNJIR,MAGARP,MAHAD,

in this i want to print text after each 120 character in the next line.

Pls help.

# 2  
Old 10-22-2008
awk '{ print substr($0,1,120)"\n"substr($0,121)}' <filename> > outfilename
# 3  
Old 10-22-2008
Quote:
Originally Posted by vikash.rastogi
..print text after each 120 character in the next line.
Code:
sed 's/\(.\{120\}\)/&\
/g' filename


Last edited by danmero; 10-22-2008 at 01:01 PM.. Reason: quote the OP
# 4  
Old 10-22-2008
Try this one:
Code:
sed 's/./&\
> /120' filename

# 5  
Old 10-23-2008
It is not working at all, is there any "fold" command in UNIX? i heared abt it but not confirm.
# 6  
Old 10-23-2008
not working at all?
Can you tell what is the expected output and provide what you tried?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count specific character of a file in each line and delete this character in a specific position

I will appreciate if you help me here in this script in Solaris Enviroment. Scenario: i have 2 files : 1) /tmp/TRANSACTIONS_DAILY_20180730.txt: 201807300000000004 201807300000000005 201807300000000006 201807300000000007 201807300000000008 2)... (10 Replies)
Discussion started by: teokon90
10 Replies

2. UNIX for Advanced & Expert Users

File name contains escape character--how to fix?

Assuming the file is supposed to be named Right is actually named: Wrong\033-b option of the ls command. There are a number of other files in that directory which start with Wrong so a move or copy starting with Wrong* isn't an option. Is there a way to identify this file to copy or move it?... (4 Replies)
Discussion started by: wbport
4 Replies

3. Shell Programming and Scripting

Finding a certain character in a filename and count the characters up to the certain character

Hello, I do have folders containing having funny strings in their names and one space. First, I do remove the funny strings and replace the space by an underscore. find . -name '* *' | while read file; do target=`echo "$file" | sed 's/... (2 Replies)
Discussion started by: tempestas
2 Replies

4. UNIX for Dummies Questions & Answers

Split a column into multiple columns at certain character count

Hey everyone, I have an issue with a client that is passing me a list of values in one column, and occasionally the combination of all the values results in more than an 255 character string. My DB has a 255 character limit, so I am looking to take the column (comma delimited file), and if it... (1 Reply)
Discussion started by: perekl
1 Replies

5. Shell Programming and Scripting

awk - count character count of fields

Hello All, I got a requirement when I was working with a file. Say the file has unloads of data from a table in the form 1|121|asda|434|thesi|2012|05|24| 1|343|unit|09|best|2012|11|5| I was put into a scenario where I need the field count in all the lines in that file. It was simply... (6 Replies)
Discussion started by: PikK45
6 Replies

6. Shell Programming and Scripting

split character

how we can split characters of a field? for example if we have a file such like below: ... 20120102 120352.5AM ... i want to get out put like this: ... 2012 01 02 12 03 52.5 AM ... (3 Replies)
Discussion started by: saeed.soltani
3 Replies

7. Shell Programming and Scripting

read the text file and print the content character by character..

hello all i request you to give the solution for the following problem.. I want read the text file.and print the contents character by character..like if the text file contains google means..i want to print g go goo goog googl google like this Using unix Shell scripting... without using... (1 Reply)
Discussion started by: samupnl
1 Replies

8. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

9. Shell Programming and Scripting

Help fix my garbage - File Split Program in Perl

Hi, I have the following, it doesn't work and I know it's crap code. The objective is to split a file with a givin number of codes such as: 01,02,03,...,99 Then return all records with each seperate identifier in a new file. The files being split have lrecl=500, recfm=F, and I... (4 Replies)
Discussion started by: mkastin
4 Replies

10. UNIX for Dummies Questions & Answers

How to split a value according to character position

Hello all, I have a script which picks up a series of large numbers, each of which are actually amalgamations of a series of other numbers. Unfortunately there are no separator characters so I can't use awk -F. I am looking for a way of splitting them into variables according to their... (4 Replies)
Discussion started by: michaeltravisuk
4 Replies
Login or Register to Ask a Question