Sponsored Content
Top Forums Shell Programming and Scripting changing a variable length text to a fixed length Post 302442065 by dc18 on Tuesday 3rd of August 2010 07:53:29 AM
Old 08-03-2010
PHP Still need solution

Hi Scott,

Input file

Code:
01,10,000020,*,*,******,999999,00,,WERK 28 - BUS
01,10,000030,*,*,******,999999,00,,WERK 30 - UNIMOG
01,10,000060,*,*,******,999999,20,,LASTWAGEN
01,10,000065,*,*,******,999999,00,,WERK 65 - TRANSP.
01,00,000001,*,*,******,999999,00,,DB-PKW
01,00,000010,*,*,******,999999,00,,DB-LKW
01,00,100012,*,*,******,999999,20,,600
01,00,100014,*,*,******,999999,20,,600 LANG 4-T RIG
01,00,100015,*,*,******,999999,20,,600 LANDAUER
01,00,100016,*,*,******,999999,20,,600 LANG 6-T RIG

Output from script, before and after, showing field length & text

Code:
   b4 change 13    WERK 28 - BUS
after change 72    WERK              28                -                 BUS
   b4 change 16    WERK 30 - UNIMOG
after change 72    WERK              30                -                 UNIMOG
     b4 change 9    LASTWAGEN
after change 18    LASTWAGEN
   b4 change 17    WERK 65 - TRANSP.
after change 72    WERK              65                -                 TRANSP.
     b4 change 6    DB-PKW
after change 18    DB-PKW
     b4 change 6    DB-LKW
after change 18    DB-LKW
     b4 change 3    600
after change 18    600
   b4 change 16    600 LANG 4-T RIG
after change 72    600               LANG              4-T               RIG
   b4 change 12    600 LANDAUER
after change 36    600               LANDAUER
   b4 change 16    600 LANG 6-T RIG
after change 72    600               LANG              6-T               RIG

Shell Script

Code:
cat infile | while read line
do
  field=`echo $line | cut -d',' -f10`
  echo "   b4 change ${#field}    $field"
  field=$(printf "%-18s" $field)
  echo "after change ${#field}    $field"
done

Thanks
Dave

Last edited by dc18; 08-03-2010 at 03:34 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

creating a fixed length output from a variable length input

Is there a command that sets a variable length? I have a input of a variable length field but my output for that field needs to be set to 32 char. Is there such a command? I am on a sun box running ksh Thanks (2 Replies)
Discussion started by: r1500
2 Replies

2. Shell Programming and Scripting

convert XML file into Text file(fixed length)

If someone out there could help me out with this problem. I would really appreciate it. I am trying to convert xml into text file(fixed length) using Unix Borne shell scripts. My xml file: <root> <header_rec recordtype="00"> <record_id>00</record_id> ... (0 Replies)
Discussion started by: ram2s2001
0 Replies

3. Shell Programming and Scripting

Combining Two fixed width columns to a variable length file

Hi, I have two files. File1: File1 contains two fixed width columns ID of 15 characters length and Name is of 100 characters length. ID Name 1-43<<11 spaces>>Swapna<<94 spaces>> 1-234<<10 spaces>>Mani<<96 spaces>> 1-3456<<9 spaces>>Kapil<<95 spaces>> File2: ... (4 Replies)
Discussion started by: manneni prakash
4 Replies

4. Shell Programming and Scripting

Comparing column of variable length anf fixed width file

Hi, I have two input files. File1: ID Name Place 1-234~name1~Newyork 1-34~name2~Boston 1-2345~name3~Hungary File1 is a variable length file where each column is seperated by delimitter "~". File2: ID Country 1-34<<11 SPACES>>USA<<7 spaces>> 1-234<<10 SPACES>>UK<<8... (5 Replies)
Discussion started by: manneni prakash
5 Replies

5. 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

6. 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

7. Shell Programming and Scripting

Make variable length record a fixed length

Very, very new to unix scripting and have a unique situation. I have a file of records that contain 3 records types: (H)eader Records (D)etail Records (T)railer Records The Detail records are 82 bytes in length which is perfect. The Header and Trailer records sometimes are 82 bytes in... (3 Replies)
Discussion started by: jclanc8
3 Replies

8. Shell Programming and Scripting

fixed length text file padding issues in AIX

Hi, I have a fixed length text file that needs to be cut into individual files in aix and facing padding issues. If I have multiple blank spaces in the file it is just making it one while cutting the files.. Eg:- $ - blank space filename:file.txt ... (2 Replies)
Discussion started by: techmoris
2 Replies

9. Shell Programming and Scripting

Extracting fixed length number from a text file

Hi, I have a text file with sample records as CASE ID: 20170218881083 Original presentment record for ARN not found for Re-presentment I want to extract the 23 digit number from this file. I thought of using grep but initially couldn't extract the required number. However, after... (16 Replies)
Discussion started by: dsid
16 Replies

10. Shell Programming and Scripting

Convert variable length record to fixed length

Hi Team, I have an issue to split the file which is having special chracter(German Char) using awk command. I have a different length records in a file. I am separating the files based on the length using awk command. The command is working fine if the record is not having any... (7 Replies)
Discussion started by: Anthuvan
7 Replies
HOSTSYNC(3PVM)							  PVM Version 3.4						    HOSTSYNC(3PVM)

NAME
pvm_hostsync - Get time-of-day clock from PVM host. SYNOPSIS
C #include <sys/time.h> int info = pvm_hostsync( int host, struct timeval *clk, struct timeval *delta ) Fortran call pvmfhostsync( host, clksec, clkusec, deltasec, deltausec, info ) PARAMETERS
host TID of host. clk (or clksec and clkusec) Returns time-of-day clock sample from host. delta (or deltasec and deltausec) Returns difference between local clock and remote host clock. DESCRIPTION
pvm_hostsync samples the time-of day clock of a host in the virtual machine and returns both the clock value and the difference between local and remote clocks. To reduce the delta error due to message transit time, local clock samples are taken before and after reading the remote clock. Delta is the difference between the mean local clocks and remote clock. Note that the delta time can be negative. The microseconds field is always normalized to 0..999999, while the sign of the seconds field gives the sign of the delta. For example: 3.25 Sec = 3,250000 0 = 0,0 -1 uSec = -1,999999 -1 Sec = -1,000000 -1.1 Sec = -2,999000 In C, if clk or delta is a null pointer, that parameter is not returned. ERRORS
If pvm_hostsync is successful, it returns PvmOk. These error conditions can be returned by pvm_hostsync PvmSysErr pvmd not responding. PvmNoHost specified host not in virtual machine. PvmHostFail host is unreachable (and thus possibly failed) SEE ALSO
pvm_config(3PVM) 20 February, 1994 HOSTSYNC(3PVM)
All times are GMT -4. The time now is 09:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy