![]() |
|
|
|
|
|||||||
| UNIX Desktop for Dummies Questions & Answers Questions regarding GNOME, KDE, CDE, Open Office, etc go here. All UNIX and Linux Newbies Welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Changing particular field in fixed width file | dsravan | Shell Programming and Scripting | 4 | 02-11-2008 02:08 PM |
| Extracting records with unique fields from a fixed width txt file | sitney | Shell Programming and Scripting | 8 | 02-09-2008 11:18 PM |
| Converting a Delimited File to Fixed width file | raghavan.aero | Shell Programming and Scripting | 2 | 06-06-2007 11:44 AM |
| adding delimiter to a fixed width file | sumeet | Shell Programming and Scripting | 2 | 03-21-2007 06:19 AM |
| Fixed Width file using AWK | alok.benjwal | UNIX for Dummies Questions & Answers | 2 | 12-05-2005 07:39 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Help with Fixed width File Parsing
I am trying to parse a Fixed width file with data as below. I am trying to assign column values from each record to variables. When I parse the data, the spaces in all coumns are dropped. I would like to retain the spaces as part of the dat stored in the variables. Any help is appreciated.
I would like to redirect this data into a csv file like below for each record 2,6138023380020080422120104828,60061395297943,0000006824, ,C, , ,POS .......etc Input File 26138023380020080422120104828600613952979430000006824C POS13MMAHONIA NANCY 4189928286000422120104CO OP 2529 HOLIDAY FLCO-OP #2529 My Script: while read LINE do a=`echo "$(echo $LINE |cut -c1-1)"` b=`echo "$(echo $LINE |cut -c2-32)"` c=`echo "$(echo $LINE |cut -c33-43)"` d=`echo "$(echo $LINE |cut -c44-53)"` e=`echo "$(echo $LINE |cut -c54-55)"` f=`echo "$(echo $LINE |cut -c55-74)"` #echo $a,$b,$c,$d,$e,"$f >> Int_4_final.dat done < $1 |
| Forum Sponsor | ||
|
|
|
|||
|
You need to use proper quoting to preserve spaces in variables. See UNIX Shell Quote
(via Answers to Frequently Asked Questions - The UNIX Forums) |
|
|||
|
If the result contains spaces, you will need to quote the backticks, too.
Code:
year="$(echo "$zf" | cut -c185-188)" car="$(echo "$zf" | cut -c189-230)" |
|||
| Google UNIX.COM |