Computing.Net > Forums > Unix > else if scripting?

else if scripting?

Reply to Message Icon

Original Message
Name: htnkd
Date: July 11, 2005 at 12:09:20 Pacific
Subject: else if scripting?
OS: unix
CPU/Ram: unix
Comment:

I need to be able to have a script that check alternate fields for alternate names. If the field is not blank than I need to print that field plus the main fields
Example:
record is a "|" delimited with 52 fields.

$1|$2|$3|$4|$5|$6|$7|$8|$9|$10|$11|$12|$13|$14|..........................$41|$42|$43|$44|$45|$46|$47|$48|$49|$50|$51|$52|

out of this record I need print the following which I can with this
gawk -F "|" '{print$3,"|",$29,"|",$27,"|",$25,"|",$18,"|",$19,"|",$21,"|",$22,"|",$41,"|",$43,"|",$45,"|",$47,"|",$49,"|",$51}'<${i}_4444.txt > ${i}_${DELIVERY}.txt

what I also need to do is check to see if $3, $41, $43, $45, $47, $49 and $51 have another name in it.
If they do than I need to print the following
$3,"|",$29,"|",$27,"|",$25,"|",$18,"|",$19,"|",$21,"|",$22
$41,"|",$29,"|",$27,"|",$25,"|",$18,"|",$19,"|",$21,"|",$22
$43,"|",$29,"|",$27,"|",$25,"|",$18,"|",$19,"|",$21,"|",$22
etc. etc..

if they do not have an alternate name continue to check each field and then continue on to the next record.

I am haveing trouble putting this into a unix script--

if you can help I would appreciate it

thanks



Report Offensive Message For Removal

Response Number 1
Name: Jim Boothe
Date: July 11, 2005 at 15:15:20 Pacific
Subject: else if scripting?
Reply: (edit)

It is not clear to me the checks you want to make on $3, $41, etc, but awk should be able to do the test.  Also, if you declare your Output Field Separator as the bar character, that will save you some coding.

Or if you want bar character AND spaces, then use: OFS=" | "

gawk -F\| 'BEGIN {OFS="|"}
{print $3,$29,$27,$25,$18,$19,$21,$22,$41,$43,$45,$47,$49,$51

 if ($3=="whatever")
    print $3,$29,$27,$25,$18,$19,$21,$22

 if ($41=="whatever")
    print $3,$29,$27,$25,$18,$19,$21,$22

 etc etc

}' ${i}_4444.txt > ${i}_${DELIVERY}.txt


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: else if scripting?

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software