Hi, guys...
I need to do a little bit of formatting with awk and I don't know what is the best way to do it when the conten of the file is slightly irregular...
Here is the sample of my input file...(This is a Maya ASCII file)
---
//Maya ASCII 4.0 scene
//Name: MayaTest.ma
//Last modified: Tue, Feb 19, 2002 05:34:13 PM
requires maya "4.0";
currentUnit -l centimeter -a degree -t film;
createNode nurbsSurface -n "nurbsSphereShape1" -p "nurbsSphere1";
setAttr -k off ".v";
setAttr ".vir" yes;
setAttr ".vif" yes;
setAttr ".tw" yes;
setAttr ".dvu" 0;
setAttr ".dvv" 0;
setAttr ".cpr" 4;
setAttr ".cps" 1;
setAttr ".nufa" 4.5;
setAttr ".nvfa" 4.5;
createNode camera -s -n "perspShape" -p "persp";
setAttr -k off ".v" no;
setAttr ".fl" 34.999999999999993;
setAttr ".coi" 44.821869662029947;
setAttr ".imn" -type "string" "persp";
setAttr ".den" -type "string" "persp_depth";
setAttr ".man" -type "string" "persp_mask";
setAttr ".hc" -type "string" "viewSet -p %camera";
createNode mesh -n "pCubeShape1" -p "pCube1";
setAttr -k off ".v";
setAttr ".vir" yes;
setAttr ".vif" yes;
setAttr ".uvst[0].uvsn" -type "string" "map1";
setAttr ".cuvs" -type "string" "map1";
createNode camera -s -n "topShape" -p "top";
setAttr -k off ".v" no;
setAttr ".rnd" no;
setAttr ".coi" 100;
setAttr ".ow" 30;
setAttr ".imn" -type "string" "top";
setAttr ".den" -type "string" "top_depth";
setAttr ".man" -type "string" "top_mask";
setAttr ".hc" -type "string" "viewSet -t %camera";
setAttr ".o" yes;
---
As you can see this file is consists of many blocks of data, and my goal is to seperate those blocks and copy them into individual files so that I could exchange them with other blocks...
Currently I am checking if the $2 is either 'mesh' or 'nurbsSurface' and if it is I copy all the 'setAttr's within the block into the external file with simple >>.
In my code, within awk statement, I have multiple if statements to check what the next token is, but I was wondering if there is any better way to do it than using multiple if statements...
---
else if (( $1 == "createNode" ) && ( $3 != "-s" ) && ( $4 ~/"/ ))
{
if (( $2 == "mesh" ) || ( $2 == "nurbsSurface" ))
{
if ( showNode == 0 )
{
showNode = 1 ; # True for showing the attributes for the node
printf "%+3s %-75s\n", x, $0 > "ObjFile.txt" ;
}
else if ( showNode == 1 )
{
printf "%+3s %-75s\n", x, $0 >> "ObjFile.txt" ;
showNode = 0 ;
}
}
else
{
showNode = 0 ;
printf "%+3s %-75s\n", x, $0 >> "EtcFile.txt" ;
}
}
---
Above if statement is just a block of many many if statements, and I have more things to check than just 'mesh' and 'nurbsSurface'...
I was thinking maybe it will be better and easier to deal with problems if I could be able to reformat the input file first before I do all the if checkings...
For example, in one of those blocks, the data goes like this...
---
createNode mesh -n "pCubeShape1" -p "pCube1";
setAttr -k off ".v";
setAttr ".vir" yes;
setAttr ".vif" yes;
setAttr ".uvst[0].uvsn" -type "string" "map1";
setAttr ".cuvs" -type "string" "map1";
---
and I want to put some dummy $1 in front of all those 'setAttr' lines so that it will look like...
---
createNode mesh -n "pCubeShape1" -p "pCube1";
xxxxx setAttr -k off ".v";
xxxxx setAttr ".vir" yes;
xxxxx setAttr ".vif" yes;
xxxxx setAttr ".uvst[0].uvsn" -type "string" "map1";
xxxxx setAttr ".cuvs" -type "string" "map1";
---
and, when exporting that block of data into the external text file, I could just somehow replace that 'xxxxx' with ' ' so that the data can be read in Maya next time... I think doing that will reduce lots of if statements in my script... But I just don't know how...
I am specifying the name of output text file name like this...
printf "%+3s %-75s\n", x, $0 >> "ObjFile.txt" ;
and I was wondering if I could use some other variable rather than specifying the name of the actual file...
When I test this script, I go like this...
./grepMaya5 MayaTest.ma
and this will create 'ObjFile.txt' and 'EtcFile.txt'...
I want those file names to be 'MayaTest.OBJ.ma' and 'MayaTest.Etc.ma'...
I tried the way I would do that in the shell script(which is working just fine) inside the awk statement and it was causing an error...
Can someone show me how to deal with these problems???
Thanks in advance...
Have a nice day!!!
Jason
I need to do a little bit of formatting with awk and I don't know what is the best way to do it when the conten of the file is slightly irregular...
Here is the sample of my input file...(This is a Maya ASCII file)
---
//Maya ASCII 4.0 scene
//Name: MayaTest.ma
//Last modified: Tue, Feb 19, 2002 05:34:13 PM
requires maya "4.0";
currentUnit -l centimeter -a degree -t film;
createNode nurbsSurface -n "nurbsSphereShape1" -p "nurbsSphere1";
setAttr -k off ".v";
setAttr ".vir" yes;
setAttr ".vif" yes;
setAttr ".tw" yes;
setAttr ".dvu" 0;
setAttr ".dvv" 0;
setAttr ".cpr" 4;
setAttr ".cps" 1;
setAttr ".nufa" 4.5;
setAttr ".nvfa" 4.5;
createNode camera -s -n "perspShape" -p "persp";
setAttr -k off ".v" no;
setAttr ".fl" 34.999999999999993;
setAttr ".coi" 44.821869662029947;
setAttr ".imn" -type "string" "persp";
setAttr ".den" -type "string" "persp_depth";
setAttr ".man" -type "string" "persp_mask";
setAttr ".hc" -type "string" "viewSet -p %camera";
createNode mesh -n "pCubeShape1" -p "pCube1";
setAttr -k off ".v";
setAttr ".vir" yes;
setAttr ".vif" yes;
setAttr ".uvst[0].uvsn" -type "string" "map1";
setAttr ".cuvs" -type "string" "map1";
createNode camera -s -n "topShape" -p "top";
setAttr -k off ".v" no;
setAttr ".rnd" no;
setAttr ".coi" 100;
setAttr ".ow" 30;
setAttr ".imn" -type "string" "top";
setAttr ".den" -type "string" "top_depth";
setAttr ".man" -type "string" "top_mask";
setAttr ".hc" -type "string" "viewSet -t %camera";
setAttr ".o" yes;
---
As you can see this file is consists of many blocks of data, and my goal is to seperate those blocks and copy them into individual files so that I could exchange them with other blocks...
Currently I am checking if the $2 is either 'mesh' or 'nurbsSurface' and if it is I copy all the 'setAttr's within the block into the external file with simple >>.
In my code, within awk statement, I have multiple if statements to check what the next token is, but I was wondering if there is any better way to do it than using multiple if statements...
---
else if (( $1 == "createNode" ) && ( $3 != "-s" ) && ( $4 ~/"/ ))
{
if (( $2 == "mesh" ) || ( $2 == "nurbsSurface" ))
{
if ( showNode == 0 )
{
showNode = 1 ; # True for showing the attributes for the node
printf "%+3s %-75s\n", x, $0 > "ObjFile.txt" ;
}
else if ( showNode == 1 )
{
printf "%+3s %-75s\n", x, $0 >> "ObjFile.txt" ;
showNode = 0 ;
}
}
else
{
showNode = 0 ;
printf "%+3s %-75s\n", x, $0 >> "EtcFile.txt" ;
}
}
---
Above if statement is just a block of many many if statements, and I have more things to check than just 'mesh' and 'nurbsSurface'...
I was thinking maybe it will be better and easier to deal with problems if I could be able to reformat the input file first before I do all the if checkings...
For example, in one of those blocks, the data goes like this...
---
createNode mesh -n "pCubeShape1" -p "pCube1";
setAttr -k off ".v";
setAttr ".vir" yes;
setAttr ".vif" yes;
setAttr ".uvst[0].uvsn" -type "string" "map1";
setAttr ".cuvs" -type "string" "map1";
---
and I want to put some dummy $1 in front of all those 'setAttr' lines so that it will look like...
---
createNode mesh -n "pCubeShape1" -p "pCube1";
xxxxx setAttr -k off ".v";
xxxxx setAttr ".vir" yes;
xxxxx setAttr ".vif" yes;
xxxxx setAttr ".uvst[0].uvsn" -type "string" "map1";
xxxxx setAttr ".cuvs" -type "string" "map1";
---
and, when exporting that block of data into the external text file, I could just somehow replace that 'xxxxx' with ' ' so that the data can be read in Maya next time... I think doing that will reduce lots of if statements in my script... But I just don't know how...
I am specifying the name of output text file name like this...
printf "%+3s %-75s\n", x, $0 >> "ObjFile.txt" ;
and I was wondering if I could use some other variable rather than specifying the name of the actual file...
When I test this script, I go like this...
./grepMaya5 MayaTest.ma
and this will create 'ObjFile.txt' and 'EtcFile.txt'...
I want those file names to be 'MayaTest.OBJ.ma' and 'MayaTest.Etc.ma'...
I tried the way I would do that in the shell script(which is working just fine) inside the awk statement and it was causing an error...
Can someone show me how to deal with these problems???
Thanks in advance...
Have a nice day!!!
Jason