-
Use a script like the following:
{
tempregion = substr($3,1,7)
tempyear = substr($2,4)
if ( tempregion == "REGROLL" && tempyear >= 1996)
printf("%s %d %s %s %f %f\n", $1,tempyear,$3,$4,$5,$6)
}
$0 refers to the whole input string - use it only if you need to print the input as is, if you need modifications print individual fields (as shown above) instead.
I have assumed that the individual fields are separated by a whitespace. Please modify appropriately if it not so.
-amar
-
some extra awk stuff
use sub() or gsub() to replace a substring in a string.
use a combination of index(),length(),substr() to replace whatever you want in the string.
Regards
Gert
-
Originally posted by amar
.
I have assumed that the individual fields are separated by a whitespace. Please modify appropriately if it not so.
-amar
Thanks Amar and denevge,
The fields are of fixed length format and are not seperated by anything.
Thanks
Anurag
Appreciation is a wonderful thing;
It makes what is excellent in others belong to us as well.
-
Hi,
The fields are fixed length and how do I make sure that the length remains the same even after substituting the string bevause I cannot use $1, $2 ... in this case.
Please Suggest.
Thanks
Anurag
Appreciation is a wonderful thing;
It makes what is excellent in others belong to us as well.
-
Modify the script as follows:
{
tmpregion = substr( $0,21,10)
tmpyear = substr($0,14,4)
if ( tmpregion == "REGROLL " && tmpyear > 1996)
printf("%s%s%s\n",substr($0,1,10),tempyear,substr($0,21))
}
Please check the relative positions of the fields. I am assuming the first field to be 10 chars, and that you want to print the rest of the record starting with "REG....".
-amar
-
Originally posted by amar
Modify the script as follows:
{
tmpregion = substr( $0,21,10)
tmpyear = substr($0,14,4)
if ( tmpregion == "REGROLL " && tmpyear > 1996)
printf("%s%s%s\n",substr($0,1,10),tempyear,substr($0,21))
}
Thanks Amar,
what this script will do is will make the second field (tempyear) of 4 characters (from the substring). I need to pad it with 6 blank spaces and then start the third field.
Any suggestions.
Thanks
Anurag
Appreciation is a wonderful thing;
It makes what is excellent in others belong to us as well.
-
{
tmpregion = substr( $0,21,10)
tmpyear = substr($0,14,4)
blanks = " "
if ( tmpregion == "REGROLL " && tmpyear > 1996)
printf("%s%s%s%s\n",substr($0,1,10),blanks,tempyear,substr($0,21))
}
-amar
-
Heck, make that
blank = "6 blanks"
-amar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|