Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to do the foolowing:

Status
Not open for further replies.

smehta

Programmer
Mar 4, 2003
5
US
I need to generate a single file based on the all the city states file I have in one directory. For example I have the file emp-name-irving-texas.grammar. I need to get the following output based on the file name:

(irving texas IRVING-TEXAS:n) {<city irving><state texas><vid $n>}

Similarly if I have the file emp-name-newyork-newyork.grammar the output would be:
Please note upper case also.

(newyork newyork NEWYORK-NEWYORK:n) {<city newyork><state newyork><vid $n>}I have to get the following output

I need to keep appending this output to one single file.
So the final file needs to look like:
[
(irving texas IRVING-TEXAS:n) {<city irving><state texas><vid $n>}
(newyork newyork NEWYORK-NEWYORK:n) {<city newyork><state newyork><vid $n>}
]

([ is appened at the top of the file and ] is appended at the end of the file.)




How may I do this in awk?

 
Do all your files have the prefix of &quot;emp-name-&quot; and the suffix of &quot;.grammer&quot;?

Then that means that a generic form of your filename would be &quot;emp-name-city-state.grammer&quot;. I know that I am stating the obvious, but sometimes that helps me think.
Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
If I could do it - it must have been really easy.

Code:
ls -1 *.grammer | awk '
BEGIN {
  FS=&quot;-&quot;
  print &quot;[&quot;
}
/grammer/ {
  city = $3
  state = substr($4,1,index($4,&quot;.&quot;)-1)
  CITY = toupper( city )
  STATE = toupper( state )
  print &quot;(&quot; city &quot; &quot; state &quot; &quot; CITY &quot;-&quot; STATE &quot;:n) {<city &quot; city &quot;><state &quot; state &quot;><vid \$n>}&quot;
}
END {
  print &quot;]&quot;
}

I hope this is what you need. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
cool, yes this works only thing now I have to mak echnage for cases where city has two parts like orange-county in that case the numbering would change, $4 would become $5 etc
 
cool, yes this works only thing now I have to mak echnage for cases where city has two parts like orange-county in that case the numbering would change, $4 would become $5 etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top