Advertisement

07.24.2008 at 11:11AM PDT, ID: 23593156
[x]
Attachment Details

parsing a file in shell script

Asked by saibsk in KornShell (ksh)

# client id: 298
298 local:/opt/intrd298.psv: norm  /opt/hold OURTXNS nocr schema@schema
298 local:/opt/incpn298.psv: norm  /opt/hold OURTXNS nocr schema@schema
298 local:/opt/inbtb298.psv: norm  /opt/hold OURTXNS nocr schema@schema
298 local:/opt/inbal298.psv: norm  /opt/hold OURBLS nocr schema@schema
298 local:/opt/inftbb298.psv: norm  /opt/hold FTBBCKS nocr schema@schema
298 local:/opt/inftbf298.psv: norm  /opt/hold FTBFRONTS nocr schema@schema
298 local:/opt/inmgl298.psv: norm  /opt/hold OURTXNS nocr schema@schema
298 local:/opt/inpos298.psv: norm  /opt/hold OURPOS nocr schema@schema

# client id: 299
299 local:/opt/intrd299.psv: norm  /opt/hold OURTXNS nocr schema@schema
299 local:/opt/incpn299.psv: norm  /opt/hold OURTXNS nocr schema@schema
299 local:/opt/inbtb299.psv: norm  /opt/hold OURTXNS nocr schema@schema
299 local:/opt/inbal299.psv: norm  /opt/hold OURBLS nocr schema@schema
299 local:/opt/inftbb299.psv: norm  /opt/hold FTBBCKS nocr schema@schema
299 local:/opt/inftbf299.psv: norm  /opt/hold FTBFRONTS nocr schema@schema
299 local:/opt/inmgl299.psv: norm  /opt/hold OURTXNS nocr schema@schema
299 local:/opt/inpos299.psv: norm  /opt/hold OURPOS nocr schema@schema

I need to have eight entries for each client in the above file. I am checking for the number of entries using this line of code

if [ `grep "^$client " $F | wc -l | sed "s/ //g"` != 8 ]
 then
echo "not 8 entries for ID $client found!"
fi
fi

But if any entry is missing I want create and append that to the existing entries for that client. If the client doesn't have entry at all I want to create all the 8 entries and append that at the end of the file using shell script. Please adviseStart Free Trial
[+][-]07.24.2008 at 08:57PM PDT, ID: 22085891

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: KornShell (ksh)
Sign Up Now!
Solution Provided By: Tintin
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628