|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
actually i am trying to find the lenght of fixed width file record reading from teradata db but its not working can u guys help me out? code which i wrote--- Code:
colmn_lngth=`cat $RPT_FILE | awk -F~ '{print $1}'`
rm $RPT_FILE
while read line
do
result=`echo $line | wc -m`
result=`expr $result - 1`
if [ $result -le $colmn_lngth ]; then
echo $line >> $Src_File.temp
else
echo $line >> $Src_File.bad
fi
done < $Src_Filebut in file if record is having spaces in between then its not counting tht spaces so it is creating wrong validation. and writing tht record in to file also its not going properly ....plzs guys can any help out with this issue.plzs Last edited by Scott; 10-04-2012 at 09:55 AM.. Reason: Code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
is this fix width right..? try Code:
awk '{ print (length($0))}' fileif it is same for all the rows.. use.. Code:
awk 'END{ print (length($0))}' file |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
'fixed width records' does not necessarily mean carriage control ("\n") at the end of a line. It just means the data are laid out in a fixed pattern, probably with no character to mark then end of the line. If it is a fixed record length file with carriage control, then just read the very first line. Code:
awk '{print length($0); exit}' infileWithout carriage control you will have a much harder time finding the record length, generally you need to get that information from a source external to the file: file metadata, specifications, someone who knows. |
|
#4
|
|||
|
|||
|
Code:
echo 123123123 | read var
echo ${#var}
9 |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
actually wht ever command which i gave is working in intractive mode but when i run d program it removing spaces in record and returning d record count d same while writing in to file.
thaxz fr reply in advance. ---------- Post updated at 10:51 AM ---------- Previous update was at 08:55 AM ---------- can any give me code fr d below Actually i am reading a record from teradata db table i.e, fixed width with spaces in between, now i want to find good record from tht file according to record length if length is more than the fixed width file length then it will remove tht error record to new file from base file. we will give file as parameter. Plzs help out in this |
| Sponsored Links | ||
|
![]() |
| Tags |
| awk, fixed width, fixed width lenght |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to find lenght of fixed width file record? | Seshendranath | UNIX for Dummies Questions & Answers | 0 | 10-04-2012 07:51 AM |
| Removing \n within a fixed width record | CKT_newbie88 | Shell Programming and Scripting | 10 | 05-01-2009 03:21 PM |
| Can we convert a '|' file into a fixed lenght??? | kumarsaravana_s | Shell Programming and Scripting | 2 | 05-30-2007 04:06 AM |
| How to insert a record in fixed width flatfile | limou | Shell Programming and Scripting | 1 | 03-13-2006 03:55 PM |
| Fixed Width file using AWK | alok.benjwal | UNIX for Dummies Questions & Answers | 2 | 12-05-2005 10:39 AM |
|
|