Computing.Net > Forums > Unix > Pushing carriage return in a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Pushing carriage return in a file

Reply to Message Icon

Name: shsandeep
Date: March 21, 2006 at 03:40:26 Pacific
OS: AIX 5.2
CPU/Ram: 1.6 GHz 12 GB RAM
Product: p570
Comment:

I have a file which has carriage returns at different positions at different lines: 47, 48, 45, etc.
I would like to have all of them aligned at position 50.
Is there any command or script which can serve the above purpose?

eg: pgm oldfile newfile
'newfile' should contain all the carriage returns/line feeds at position 50.

Thanks.




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 21, 2006 at 07:10:16 Pacific
Reply:

First, in unix lines are terminated with just a LF - not a CR/LF.

There's a number of ways to do this. The printf command will work:

#!/bin/ksh

while read line
do
printf "%-50.50s\n" "$line"
done < data.file > newdata.file

You can also use any programming environment that uses printf such as perl or awk:

awk '{ printf("%-50.50s\n", $0) }' data.file > newdata.file



0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Pushing carriage return in a file

Cancel Out lines in a file www.computing.net/answers/unix/cancel-out-lines-in-a-file/6765.html

deleting rows in a file www.computing.net/answers/unix/deleting-rows-in-a-file/3676.html

how to replace a line in a file www.computing.net/answers/unix/how-to-replace-a-line-in-a-file/7214.html