Uniform length for all the lines in file

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Uniform length for all the lines in file
# 1  
Old 08-28-2009
Power Uniform length for all the lines in file


I have a file with different width for each line. like first line with 45characters and second line of 30 characters. But I want to make all the lines to 45 characters in file.

Appreciate your inputs

# 2  
Old 08-28-2009
One way. Assuming this is a normal text file.

while read line
        printf '%-45s\n' "${line}"
) <myfile >myfile.new

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter all the lines with minimum specified length of words of a text file

Hi Can someone tell me which script will work best (in terms of speed and simplicity to write and run) for a large text file to filter all the lines with a minimum specified length of words ? A sample script with be definitely of great help !!! Thanks in advance. :) (4 Replies)
Discussion started by: my_Perl
4 Replies

2. Shell Programming and Scripting

Deleting lines in a fixed length file where there is a word at specific location

I have a big file having 100 K lines. I have to read each line and see at 356 character position whethere there is a word "W" in it. If it is their then don't delete the line otherwise delete it. There are two lines as one Header and one trailer which should remain same. Can somebody... (5 Replies)
Discussion started by: mohit kanoongo
5 Replies

3. Shell Programming and Scripting

Filter file by length, looking only at lines that don't begin with ">"

I have a file that stores data in pairs of lines, following this format: line 1: header (preceded by ">") line 2: sequence Example.txt: >seq1 name GATTGATGTTTGAGTTTTGGTTTTT >seq2 name TTTTCTTC I want to filter out the sequences and corresponding headers for all sequences that are less... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

4. Shell Programming and Scripting

How can I format a text file into uniform columns?

I have a file : e.g. Charles Dixon Age 23 Hometown Darlington Postcode DL1 2DC Fred Bixton Age 34 Hometown Leeds Postcode LS1 5XS Jim Davis Age 48 Hometown Cardiff CF2 8YY Is it possible to format this file into uniform columns using, say, the spaces as... (11 Replies)
Discussion started by: bigbuk
11 Replies

5. Shell Programming and Scripting

Flat file-make field length equal to header length

Hello Everyone, I am stuck with one issue while working on abstract flat file which i have to use as input and load data to table. Input Data- ------ ------------------------ ---- ----------------- WFI001 Xxxxxx Control Work Item A Number of Records ------ ------------------------... (5 Replies)
Discussion started by: sonali.s.more
5 Replies

6. Shell Programming and Scripting

Delete lines where line length is < x

Hi all, I am using Sed to convert a log file into a csv, so far so good. Kudos to this forum for helping me thus far! My current problem. There are some lines in the log file that I do not want. How can I delete lines where the line legth is less than say 100? Here are some sample lines... (6 Replies)
Discussion started by: Mr. Rocco
6 Replies

7. Shell Programming and Scripting

How to add trailing spaces to have file with lines of the same length?

I have textfile (source.txt) with different length of lines in it. Can anybody help to compose a script under bash which would add suitable number of trailing spaces to the end of each line so that after the processing the each line would have the same (let's say 100 char) length? Output can be... (6 Replies)
Discussion started by: sameucho
6 Replies

8. UNIX for Dummies Questions & Answers

Convert a tab delimited/variable length file to fixed length file

Hi, all. I need to convert a file tab delimited/variable length file in AIX to a fixed lenght file delimited by spaces. This is the input file: 10200002<tab>US$ COM<tab>16/12/2008<tab>2,3775<tab>2,3783 19300978<tab>EURO<tab>16/12/2008<tab>3,28523<tab>3,28657 And this is the expected... (2 Replies)
Discussion started by: Everton_Silveir
2 Replies

9. UNIX for Dummies Questions & Answers

What the command to find out the record length of a fixed length file?

I want to find out the record length of a fixed length file? I forgot the command. Any body know? (9 Replies)
Discussion started by: tranq01
9 Replies

10. UNIX for Dummies Questions & Answers

Sed working on lines of small length and not large length

Hi , I have a peculiar case, where my sed command is working on a file which contains lines of small length. sed "s/XYZ:1/XYZ:3/g" abc.txt > xyz.txt when abc.txt contains lines of small length(currently around 80 chars) , this sed command is working fine. when abc.txt contains lines of... (3 Replies)
Discussion started by: thanuman
3 Replies
Login or Register to Ask a Question