text processing ( sed/awk)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting text processing ( sed/awk)
# 1  
Old 02-29-2008
text processing ( sed/awk)

hi..
I have a file having record on in 1 line....

I want every 400 characters in a new line...

means in 1st line 1-400
in 2nd line - 401-800 etc


pl help.
# 2  
Old 02-29-2008
Quote:
Originally Posted by anchal_khare
hi..
I have a file having record on in 1 line....

I want every 400 characters in a new line...

means in 1st line 1-400
in 2nd line - 401-800 etc


pl help.
Code:
sed -e "s/.\{400\}/&\n/g" file.txt

# 3  
Old 02-29-2008
hi vino...
its not working..
its showing me the same output...
i tested in a small file having abcdefghijklmopqrstuvwxyz in a line....

so after -e "s/.\{4\}/&\n/g" file.txt

the output should be
abcd
efgh
ijkl
lmno
...
...


but its unchaged..

pl help
# 4  
Old 02-29-2008
script


total_chars=`wc -c filename | cut -c 1-8 `
block_size=400
cut_from=1
cut_to=400
total_chars=`expr $total_chars + 0`
#The above step is to get total_chars treated as number for below comparison
while [ $cut_from -le $total_chars ]
do
cut -c `echo $cut_from`-`echo $cut_to` filename >> outfile
cut_from=`expr $cut_from + $block_size`
cut_to=`expr $cut_to + $block_size`
done
# 5  
Old 02-29-2008
A solution with awk:

Code:
awk 'BEGIN{nr=1}{while(substr($0,nr,400)){print substr($0,nr,400);nr+=400}}' file

Regards
# 6  
Old 02-29-2008
Thanks Franklin52,Smilie

hi anchal_khare,

u can also check the below code

awk '{n=1;while( n<=length($0)) { t = substr($0,n,4); print t"\n"; n= n+4} }' Filename

Input:
abcdefghijklmnopqrstuvwxyz

output
abcd

efgh

ijkl

mnop

qrst

uvwx

yz
# 7  
Old 02-29-2008
very thanks for evy1 soln....
'll use any of thm...

1 request .. can any1 chk the vino's soln.. why its nor working...
logic seems to be current,,, but i cunt find out the error...

thanks again..

anchal.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk for text processing

Hi,my file is in this format ", \"symbol\": \"Rbm38\" } ]" I want to convert it to a more user readable format _id pubmed text symbol 67196 18667844 Overexpression of UBE2T in NIH3T3 cells significantly promoted colony formation in mouse cell cultures Ube2t 56190 21764855 ... (3 Replies)
Discussion started by: biofreek
3 Replies

2. Shell Programming and Scripting

Text replacement with awk or sed?

Hi guys, I worked for almost a half-day for the replacement of some text automatically with script. But no success. The problem is I have hundred of files, which need to be replaced with some new text. It's a painful work to work manually and it's so easy to do it wrong. For example, I... (2 Replies)
Discussion started by: liuzhencc
2 Replies

3. Shell Programming and Scripting

Text columns processing using awk

P { margin-bottom: 0.25cm; line-height: 120%; }CODE.cjk { font-family: "WenQuanYi Micro Hei",monospace; }CODE.ctl { font-family: "Lohit Hindi",monospace; }A:link { } I'm trying to build an awk statement to print from a file (file1): A 1,2,3 * A 4,5,6 ** B 1 ... (4 Replies)
Discussion started by: dovah
4 Replies

4. Shell Programming and Scripting

Text processing using awk

I dispose of two tab-delimited files (the first column is the primary key): File 1 (there are multiple rows sharing the same key, I cannot merge them) A 28,29,30,31 A 17,18,19 B 11,13,14,15 B 8,9File 2 (there is one only row beginning with a given key) A 2,8,18,30,31 B ... (3 Replies)
Discussion started by: dovah
3 Replies

5. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

6. Shell Programming and Scripting

Awk text processing

Hi Very much appreciate if somebody could give me a clue .. I undestand that it could be done with awk but have a limited experience. I have the following text in the file 1 909 YES NO 2 500 No NO . ... 1 ... (8 Replies)
Discussion started by: zam
8 Replies

7. Shell Programming and Scripting

text transformation with sed or awk

Hi there, I'm trying to extract automatically opening hours from a website. The page displaying the schedules is http://www.natureetdecouvertes.com/pages/gener/view_FO_STORE_corgen.asp?mag_cod=xxx with xxx going from 101 to 174 I managed to get the following output : le lundi de 10.30 ... (4 Replies)
Discussion started by: chebarbudo
4 Replies

8. Shell Programming and Scripting

awk, perl Script for processing a single line text file

I need a script to process a huge single line text file: The sample of the text is: "forward_inline_item": "Inline", "options_region_Australia": "Australia", "server_event_err_msg": "There was an error attempting to save", "Token": "Yes", "family": "Family","pwd_login_tab": "Enter Your... (1 Reply)
Discussion started by: hmsadiq
1 Replies

9. Shell Programming and Scripting

Preparing LaTeX files using Sed/AWK for processing with latex2html

As the title states, my issue involves preparing LaTeX documents for processing with latex2html. Within my LaTeX docs I have used a package which allows me to cleanly display source code listings. However the package is not supported by latex2html which, when processed, does not display the... (3 Replies)
Discussion started by: oski
3 Replies

10. Shell Programming and Scripting

processing a file with sed and awk

Hello, I have what is probably a simple task in text manipulation, but I just can't wrap my brain around it. I have a text file that looks something like the following. Note that some have middle initials in the first field and some don't. john.r.smith:john.smith@yahoo.com... (4 Replies)
Discussion started by: manouche
4 Replies
Login or Register to Ask a Question