![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Changing particular field in fixed width file | dsravan | Shell Programming and Scripting | 4 | 02-11-2008 06:08 PM |
| Extracting records with unique fields from a fixed width txt file | sitney | Shell Programming and Scripting | 8 | 02-10-2008 03:18 AM |
| Converting a Delimited File to Fixed width file | raghavan.aero | Shell Programming and Scripting | 2 | 06-06-2007 02:44 PM |
| adding delimiter to a fixed width file | sumeet | Shell Programming and Scripting | 2 | 03-21-2007 10:19 AM |
| Fixed Width file using AWK | alok.benjwal | UNIX for Dummies Questions & Answers | 2 | 12-05-2005 11:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
|
||||
|
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)" |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|