Help with Fixed with data


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with Fixed with data
# 1  
Old 03-12-2012
Help with Fixed width data

Hi


I have a data with varying length i need to convert it to data of fixed length 1000 by appending blank spaces. This has to be done only for specific records i tried with awk but it not happening.

Pls suggest me some advices
Code:
 awk '/^500/ {$0=sprintf("%s%t" w-length "s", $0,x)}1' w=999 /test.

but this is not yielding desired output

Last edited by vbe; 03-28-2012 at 10:00 AM..
# 2  
Old 03-12-2012
Something like this?

Code:
awk '/^500/ {printf "%-100s", $0}'1 inputfile

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 03-12-2012
How do we represent space in unix bala?
# 4  
Old 03-12-2012
Try:
Code:
awk '/^500/{$0=sprintf("%-"w"s", $0)}1' w=1000

What is bala ?
This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 03-12-2012
Does "%-" give us spaces in unix scrutnizer?
# 6  
Old 03-12-2012
Ha, ha, ha Smilie Scrutinizer, akshay01987 has shortened my alias name to 'bala'.

@akshay01987: '-' tells printf to pad spaces after the string. So, "%-10s" would print "hello" as "hello<5-spaces>". A simple "%10s" would print "<5-spaces>hello".
This User Gave Thanks to balajesuri For This Post:
# 7  
Old 03-12-2012
Doh... Smilie
Aks, in printf formatting %-1000s means left align the argument in a field that is 1000 characters wide (If the field is wider than the argument pad with spaces).
This User Gave Thanks to Scrutinizer For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk issue splitting a fixed-width file containing line feed in data

Hi Forum. I have the following script that splits a large fixed-width file into smaller multiple fixed-width files based on input segment type. The main command in the script is: awk -v search_col_pos=$search_col_pos -v search_str_len=$search_str_len -v segment_type="$segment_type"... (8 Replies)
Discussion started by: pchang
8 Replies

2. Post Here to Contact Site Administrators and Moderators

How to sum up data in fixed width file with decimal point?

HI Everyone, I have below source file AAA|NAME1|ADDRESS1|300.20 BBB|NAME2|ADDRESS2|400.31 CCC|NAME3|ADDRESS3|300.34 I have requirement where I need to sum up fourth field in above fixed width pipe delimited flat file. When I use below code, it gives me value 1001.00 But I am expecting... (1 Reply)
Discussion started by: patricjemmy6
1 Replies

3. Shell Programming and Scripting

Ignore Header and Footer and Sort the data in fixed width file

Hi Experts, I want to Sort the data in fixed width file where i have Header and Footer also in file. I m using below commad to do the sort based on field satarting from 15 position to 17 position , but it is not ignoring the Header and Footer of the file while sorting. In the output i am... (5 Replies)
Discussion started by: sasikari
5 Replies

4. Shell Programming and Scripting

Fixed length fields

HPUX and posix shell Hi all. I have a record with fixed length fields....I would like to reorder the fields and preserver the fixed lengths.... cat test 4 960025460 Dept of Music 8 960025248 Dept of Music 12-08 cat... (3 Replies)
Discussion started by: lyoncc
3 Replies

5. Shell Programming and Scripting

Getting a string without fixed delimiters

I have a line of text for example aaaa bbbb cccc dddd eeee ffffff I would need to get the cccc however bbbb could be there or not. So whether bbbb is in the line or not I need cccc. I was looking at either awk or sed....and trying to start at c and end until the next space. Also... (11 Replies)
Discussion started by: bombcan1
11 Replies

6. Shell Programming and Scripting

Script need to get fixed

I need immediate help with this code. I do want to through the output of query into the log file and then on behelf of result i do want to automate an email warning system. while compiling this code i failed to through the output into the log file. To avoid manual password change for... (3 Replies)
Discussion started by: asifrafiqe
3 Replies

7. Shell Programming and Scripting

row to column and position data in to fixed column width

Dear friends, Below is my program and current output. I wish to have 3 or 4 column output in order to accomodate in single page. i do have subsequent command to process after user enter the number. Program COUNT=1 for MYDIR in `ls /` do VOBS=${MYDIR} echo "${COUNT}. ${MYDIR}" ... (4 Replies)
Discussion started by: baluchen
4 Replies

8. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

9. Shell Programming and Scripting

Fixed Format File

Hi to All, Would you please help me. I have a issue like in fixed format file there are 80 words should be there. but if file contains greater than 80 words then creates problem. so i have to trim file having more than 80 characters line through unix shell scripting. Please let me know how... (2 Replies)
Discussion started by: div_Neev
2 Replies
Login or Register to Ask a Question