Visit Our UNIX and Linux User Community

fixed record length

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting fixed record length
# 8  
Old 03-27-2006
while read LINE
   echo |awk -v LIN="${LINE}" '{print substr(LIN,1,6)","substr(LIN,7,5)" ,"substr(LIN,13,4)","substr(LIN,17,3)" ,"substr(LIN,21,4)}'
done < INPUT

# 9  
Old 03-27-2006
it rocks Smilie

how I will use it like this:
instead of
echo |awk -v LIN="${LINE}"
to use plain $0
'{print substr($0,1,6)","substr($0,7,5)" ,"...

I guess the problem will be with field seperator -F" ? "

any idea??

# 10  
Old 03-27-2006

awk -v LIN="${0}"  ........etc

# 11  
Old 03-27-2006
I get some strage results!

awk -v LIN="${0}" '{print substr(LIN,1,6)","substr(LIN,7,5)" ,"substr(LIN,13,4)","substr(LIN,17,3)
" ,"substr(LIN,21,4)}' < file.txt > result.txt

# 12  
Old 03-28-2006
you got me wrong

Originally Posted by george_
it doesn't solve the problem...

in each file I have to change
substr parameters
instead of substr($1,7,11)" ,"substr($2,1,4)","substr($2,5,7)"

I want substr($the_whole_line,7,11),substr($the_whole_line,12,17)

ls that possible?

what I meant there is that if the no. of characters excluding spaces is constant, then you can first use sed to remove the spaces.
After that use
awk '{print substr($1,7,11) substr($1, m,n)........}' filename

once you remove the blank spaces , there will be only one field in each record so you can easily use substr on it.

# 13  
Old 03-28-2006
<what I meant there is that if the no. of characters excluding spaces is constant

including spaces is constant Smilie
# 14  
Old 03-28-2006
Originally Posted by george_
<what I meant there is that if the no. of characters excluding spaces is constant

including spaces is constant Smilie
can you post example data. With atleast two different formats and the expected output in each case

Previous Thread | Next Thread
Test Your Knowledge in Computers #266
Difficulty: Easy
In 1952, Alan Turing was prosecuted for homosexual acts a criminal offense in the UK and accepted chemical castration treatment as an alternative to prison.
True or False?

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Make it to fixed length

Hi Team, I have a different length records in my text file.I would like to make all the records with same length. I want to check the maximum lenth and all other records make the same length It's urgent request. Thanks in Advance (2 Replies)
Discussion started by: Anthuvan
2 Replies

3. Shell Programming and Scripting

Add substring in a file containing fixed length record.

I am new to awk and writing a script using awk. I have file containing fixed length records, I wish to extract 2 substring(each substring is padded with zeros on left e.g 000000003623) and add each substring respectively for every record in the file to get total sum of respective substring for all... (5 Replies)
Discussion started by: Devesh5683
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

changing a variable length text to a fixed length

Hi, Can anyone help with a effective solution ? I need to change a variable length text field (between 1 - 18 characters) to a fixed length text of 18 characters with the unused portion, at the end, filled with spaces. The text field is actually field 10 of a .csv file however I could cut... (7 Replies)
Discussion started by: dc18
7 Replies

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

7. Shell Programming and Scripting

search and replace fixed length record file

Hi I need to be search a file of fixed length records and when I hit a particular record that match a search string, substitute a known position field In the example file below FHEAD000000000120090806143011 THEAD0000000002Y0000000012 P00000000000000001234 TTAIL0000000003... (0 Replies)
Discussion started by: nedkelly007
0 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. 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

Featured Tech Videos