new line after n'th character in text file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting new line after n'th character in text file
# 1  
Old 08-01-2012
new line after n'th character in text file

Gurus,

I have a text file having only one row having following data.
Code:
640.0800     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25  640.2324     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25   640.3848     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25

. is there any way i can get result like following ( enter after every 9th column)
Code:
640.0800     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25
640.2324     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25
640.3848     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25     -999.25




Thanks

Last edited by Scrutinizer; 08-01-2012 at 05:46 AM.. Reason: code tags
# 2  
Old 08-01-2012
Like this?
Code:
awk '{gsub(/([^ \t]+[ \t]+){9}/,"&"RS)}1' infile

This User Gave Thanks to elixir_sinari For This Post:
# 3  
Old 08-01-2012
Code:
awk '{for(i=1;i<=NF;i++)if(i%9){printf("%s ",$i)}else{printf("%s\n",$i)}}' input.txt

This User Gave Thanks to itkamaraj For This Post:
# 4  
Old 08-01-2012
Hi

Code:
awk '{for(i=10;i<=NF;i+=9)$i=RS $i;}1' file

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 5  
Old 08-01-2012
Gurus,
it was my first mail to forum, and I got the result very fast, I appreciate the help from the respected member of this forum. Thanks a lot. Please find the results of the suggestion provided.

@ Elixir_Sinari - It is printing the result same as the main file. No change.
@ itkamaraj- It is working as expected.
@Guru- It is working as expected.
@Scrutinizer - It is working as expected
Thanks a lot .
Regards
Amit

Last edited by Amit.saini333; 08-02-2012 at 01:41 AM..
# 6  
Old 08-01-2012
If the output does not need to be TAB-separated
Code:
xargs -n9 < infile

This User Gave Thanks to Scrutinizer 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

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. Shell Programming and Scripting

How to accept command line argument as character or text if number is entered?

Hello Does the unix korn shell provide a function to convert number entered in command line argument to text or Character so that in next step i will convert Chr to Hex (6 Replies)
Discussion started by: aadityapatel198
6 Replies

3. Programming

Read text from file and print each character in separate line

performing this code to read from file and print each character in separate line works well with ASCII encoded text void preprocess_file (FILE *fp) { int cc; for (;;) { cc = getc (fp); if (cc == EOF) break; printf ("%c\n", cc); } } int main(int... (1 Reply)
Discussion started by: khaled79
1 Replies

4. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

how to remove all text including 2 certain character in each line!

Hi I have a file which has aroun 200 line and it is like this: GROUP2-WDI">GROUP2-WDI GROUP3-WDI">GROUP3-WDI KL2P0508BC">KL2P0508BC KL2P0508BIT">KL2P0508BIT KL3P0506BC">KL3P0506BC KL3P0506BUS">KL3P0506BUS KLD1F0507DBT">KLD1F0507DBT KLD1F0507DIT">KLD1F0507DIT KLD1F0510DBT">KLD1F0510DBT... (3 Replies)
Discussion started by: digitalmahdi
3 Replies

6. HP-UX

How to remove new line character and append new line character in a file?

Hi Experts, I have data coming in 4 columns and there are new line characters \n in between the data. I need to remove the new line characters in the middle of the row and keep the \n character at the end of the line. File is comma (,) seperated. Eg: ID,Client ,SNo,Rank 37,Airtel \n... (8 Replies)
Discussion started by: sasikari
8 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

PHP header text/csv unwanted line feed character

We have successfully created a comma delimited file, the results are correct from an sql database query. When using the following headers to print the file using print $data, an extra line feed is added and a blank row appears on the top of the data in Excel: header("Expires: 0"); ... (0 Replies)
Discussion started by: ifimbres
0 Replies

9. Shell Programming and Scripting

Awk not working due to missing new line character at last line of file

Hi, My awk program is failing. I figured out using command od -c filename that the last line of the file doesnt end with a new line character. Mine is an automated process because of this data is missing. How do i handle this? I want to append new line character at the end of last... (2 Replies)
Discussion started by: pinnacle
2 Replies

10. UNIX for Dummies Questions & Answers

Need to serach if a new line character exists on the last line in a file

I have a file in which I need to search if a new line character exists on the last line in the file. Please let me know how can I achieve it using Unix commands? (10 Replies)
Discussion started by: sunilbm78
10 Replies
Login or Register to Ask a Question