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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

more than one input and output file

Status
Not open for further replies.

tini1208

Technical User
Feb 13, 2006
56
DE
hi all,

it every time the same problem i have and i hope to find the solution here.
my script file:

Code:
BEGIN {print "UTC	shot_time	ID	lat	lon	ele	ocElev	oc_load	sat_corr	sat_corr_flg	sigma_elev"
}
$1 == "i_UTCTime"{
	for(i=0; i<40; i++){
        UTC[i]=$3}
}
$1 == "i_dShotTime"{
        shot_time[0]=0
	shot_time[1]=$3
	shot_time[2]=$4
	shot_time[3]=$5
	shot_time[4]=$6
	getline
	shot_time[5]=$1
	shot_time[6]=$2
	shot_time[7]=$3
	shot_time[8]=$4
	shot_time[9]=$5
	shot_time[10]=$6
	getline
	shot_time[11]=$1
	shot_time[12]=$2
	shot_time[13]=$3
	shot_time[14]=$4
	shot_time[15]=$5
	shot_time[16]=$6
	getline
	shot_time[17]=$1
	shot_time[18]=$2
	shot_time[19]=$3
	shot_time[20]=$4
	shot_time[21]=$5
	shot_time[22]=$6
	getline	
	shot_time[23]=$1
	shot_time[24]=$2
	shot_time[25]=$3
	shot_time[26]=$4
	shot_time[27]=$5
	shot_time[28]=$6
	getline
	shot_time[29]=$1
	shot_time[30]=$2
	shot_time[31]=$3
	shot_time[32]=$4
	shot_time[33]=$5
	shot_time[34]=$6
	getline
	shot_time[35]=$1
	shot_time[36]=$2
	shot_time[37]=$3
	shot_time[38]=$4
	shot_time[39]=$5
}
...
...
...
$1 == "i_SigmaElv"{
	sigma_elev[0]=$3
	sigma_elev[1]=$4
	sigma_elev[2]=$5
	sigma_elev[3]=$6
	sigma_elev[4]=$7
	sigma_elev[5]=$8
        getline 
	sigma_elev[6]=$1
	sigma_elev[7]=$2
	sigma_elev[8]=$3
	sigma_elev[9]=$4
	sigma_elev[10]=$5
	sigma_elev[11]=$6
	sigma_elev[12]=$7
	sigma_elev[13]=$8
	sigma_elev[14]=$9
	sigma_elev[15]=$10
	getline
	sigma_elev[16]=$1
	sigma_elev[17]=$2
	sigma_elev[18]=$3
	sigma_elev[19]=$4
	sigma_elev[20]=$5
	sigma_elev[21]=$6
	sigma_elev[22]=$7
	sigma_elev[23]=$8
	sigma_elev[24]=$9
	sigma_elev[25]=$10
	getline
	sigma_elev[26]=$1
	sigma_elev[27]=$2
	sigma_elev[28]=$3
	sigma_elev[29]=$4
	sigma_elev[30]=$5
	sigma_elev[31]=$6
	sigma_elev[32]=$7
	sigma_elev[33]=$8
	sigma_elev[34]=$9
	sigma_elev[35]=$10
	getline
	sigma_elev[36]=$4
	sigma_elev[37]=$4
	sigma_elev[38]=$4
	sigma_elev[39]=$4
	for (i=0; i<40; i++){
       OFS="\t"; print UTC[i],shot_time[i],ID[i],lat[i],lon[i],ele[i],ocElev[i],oc_load[i],sat_corr[i],sat_corr_flg[i],sigma_elev[i]}
}

now....i want to have a list of input files and the same number output files, only the extension should be changed.
i am sure, there will be a simple solution but i can't find it.

thanks so far....
 
Hi

Then why no process each file separately ?

Anyway, if you are sending all the output to stdout, then will be one output. But you can write the output to a file.

I will not analyze you lengthy code, here is a simple example of copying the lines from multiple input files with .txt extension to files with the same name but .hmm extension :
Code:
awk 'FNR==1{if(f)close(f);f=FILENAME;sub(/\.[^.]+$/,".hmm",f)}{print>f}END{close(f)}' *.txt

Feherke.
 
hi feherke,

thanks for your answer!!
i have a plenty of files and that's why a try to use only one command.

yes...my code is not short...and it's only a part of it ;-).

another maybe stupid question: is the code at the beginning of the script or at the end? i am a bit confused of this code....but i try to understand it.

cheers
 
Hi

Sorry, I do not understand your question. But I think you did not understood my intension. I posted only an example of how you can [tt]print[/tt] to separate files based on the input file name, when processing more files.
Code:
awk '
FNR==1 {                    [gray]# if this is the first line of an input file[/gray]
  if (f)                    [gray]# if already had output file[/gray]
    close(f)                [gray]#   then close it[/gray]
  f=FILENAME                [gray]# output file's name based on input file name[/gray]
  sub(/\.[^.]+$/,".hmm",f)  [gray]# but with extension changed to .hmm[/gray]
}
{                           [gray]# for all input lines[/gray]
  print > f                 [gray]# print the input line to the output file[/gray]
}
END {                       [gray]# after all processing is done[/gray]
  close(f)                  [gray]# close the last output file too[/gray]
}
' *.txt                     [gray]# process all *.txt files[/gray]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top