Help with varying data


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with varying data
# 1  
Old 02-08-2012
Help with varying data

I have flat file in which the length of the a record is 1000 characters. the last field of the file range is from 951 to 1000. So currently i am getting the last field data to be less than 1000 characters ( from 951 to 1000 i see that the data varies from 10 to 50). So is there a way we can pad up these kind of data with 0and ensure it is of size of the last field of the record is 50 and total row length is 1000.
# 2  
Old 02-08-2012
printf (available in shell and in most languages) may be what you require (hard to tell from your post to be honest, could do with a bit of clarification)
# 3  
Old 02-08-2012
Code:
perl -ne 'chomp;print "$_","0"x(1000-length($_)),"\n"' inputfile

# 4  
Old 02-10-2012
Example

Input : 2343.........456( 1 record of 934 char)
3465.........345( 1 record of 60 char)
output :2343..........456000...00(1 record of 1000 char)
3465.........345(1 record of 60 char)

I ll hav to convert the records of varying length in a flat file to a record of size 1000 by padding neccesary zeros at the end. And also this should be done for record starting with 2343 only. Rest of records should be intact
# 5  
Old 02-11-2012
Try:
Code:
awk '/^2343/{$0=sprintf("%s%0" w-length "s", $0,x)}1' w=1000 infile

# 6  
Old 02-13-2012
HI Scrutnizer

I have a data that is primarily consist of integer and the code you suggested is not working fine. is htere any change i wwill have to make ?
# 7  
Old 02-13-2012
Hi, Akshay, what isn't working fine?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge lines with varying characters

Hi, I have a large set of data (firewall logs) that I'm trying to summarize. I've been able to write a script to consolidate the ports, now am looking to conslidate even further, based on IP. Source Destination Type Port 192.168.5.108 192.168.11.12 TCP 1, 2, 3, 4, 5, 15 192.168.5.109... (6 Replies)
Discussion started by: umang2382
6 Replies

2. Shell Programming and Scripting

How to separate data with varying amounts of underscores?

All, I've searched and haven't found a solution for my particular issue. I have a file with lines of data that contain varying amounts of underscores imbedded. But all the strings have a final underscore and an interface name: dmk_hcn_dalian2.XXXX.XXX.XX.COM_Se0/0/0... (4 Replies)
Discussion started by: turk22
4 Replies

3. Shell Programming and Scripting

Paste files of varying lengths

I have three files of varying lengths and different number of columns. How can I paste all three with all columns aligned? File1 ---- 123 File2 ---- 234 345 678 File3 ---- 456 789 Output should look like: 123 234 456 345 789 (6 Replies)
Discussion started by: Un1xNewb1e
6 Replies

4. Shell Programming and Scripting

Insert varying length spaces between words

Hey all, Fist post, so be kind... I have written an expect script which logs into a terminal and gathers several screens of information. Unfortunately the log file gives me all the special escape and control characters from the terminal. I am hoping to use a combination of shell scripting, sed,... (1 Reply)
Discussion started by: mpacer
1 Replies

5. Shell Programming and Scripting

How to check the varying file size

How to know a file is of fixed file or not over a span of time Actually my requirement is to check the size of the file in a specific directory for 60 seconds, and if it remains the same then I have to move to some other directory.Else I have to stop the execution. Request you to guide me in... (4 Replies)
Discussion started by: av_vinay
4 Replies

6. Shell Programming and Scripting

substitution of varying digits

I had a requirement in which in need to pan(*) out digits except the first six visible, followed by six *, and rest visible of a variable(input) ex: Input - 123456789012345 Output - 123456******345 ex: Input - 1234567890123456 Output - 123456******3456 so i tried something like... (12 Replies)
Discussion started by: mad_man12
12 Replies

7. Shell Programming and Scripting

extract string from varying delimiter line

Hi I have lines like this a=1, b=2, c=3, a=1, d=4, e=5, b=225, I need to extract the b=nnn... value. I dont know how many other entries will be before and after it in each line. Ive tried a basic line like awk '/b=/, $NF ~ /,/ ' myfile.txt but I think that it doesnt care which comma it... (5 Replies)
Discussion started by: rebelbuttmunch
5 Replies

8. Shell Programming and Scripting

Varying number of awk search strings

I've created an awk script that handles a varying number of search strings handed to it as command line parameters ($1 $2 etc). There may be 1, or 2 or 3 or more. A simplified version of the script is: awk -v TYP="$1 $2 $3 $4 $5 $6" ' BEGIN { CTYP = split (TYP,TYPP," ") } ... (2 Replies)
Discussion started by: CarlosNC
2 Replies

9. Shell Programming and Scripting

Parse apart strings of comma separated data with varying number of fields

I have a situation where I am reading a text file line-by-line. Those lines of data contain comma separated fields of data. However, each line can vary in the number of fields it can contain. What I need to do is parse apart each line and write each field of data found (left to right) into a file.... (7 Replies)
Discussion started by: 2reperry
7 Replies

10. Shell Programming and Scripting

deleting a varying amount of lines from a list of files

I did search the posts for info on this and while there were some in the ballpark, none addressed this specifically. (also I tried to post this once it said I was logged out, so hopefully I'm not sending a duplicate here). I have a set of files (250 +/-) where I need to delete the first "$x"... (4 Replies)
Discussion started by: benair
4 Replies
Login or Register to Ask a Question