Processing a file in shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Processing a file in shell
# 1  
Old 06-28-2007
Processing a file in shell

I have a file which is having enrties like

entry-id 1

ABC : value
DEF :value
GHI :VALUE


entry-id 2
ABC : value
DEF :value
GHI :VALUE

entry-id 2
ABC : value
DEF :value
GHI :VALUE

and so on .. .wht i want to do is
to see if all the 3 items are present under each enrty-id and each one is havng some lavue ( not null)

is ther any simple way to do this


Thanks in adavance
binu
# 2  
Old 06-29-2007
A possible solution (not a simple one) :

Code:
awk -v Items_list="ABC DEF GHI" '
   BEGIN {
      FS      = ":" ;
      Unset   = 0;
      Null    = 1;
      Valid   = 2;
      Invalid = 0;
      Items_count = split(Items_list,  Items, / /);
   }

   function initEntry (entry,    i) {
      Entry_name  = entry;
      for (i=1; i<=Items_count; i++)
         Items_state[Items[i]] = Unset;
   }

   function printEntry (    i, e_state, i_state, err, errors) {
      if (! Entry_name) return;
      e_state = Valid;
      for (i=1; i<=Items_count; i++) {
         i_state = Items_state[Items[i]];
         if (i_state != Valid) {
            err    = "     " (i_state == Unset ? "Unset: " : "Null : ") Items[i];
            errors = errors (e_state == Invalid ? "\n" : "") err;
            e_state = Invalid;
         }
      }
      if (e_state == Valid) 
         print "Ok :", Entry_name;
      else {
         print "Err:", Entry_name;
         print errors;
      }
   }

   /^entry-id/ {
      printEntry();
      initEntry($0);
      next;
   }

   {
      gsub(/[[:space:]]/, "", $1);
      gsub(/[[:space:]]/, "", $2);
      if ($1 && $1 in Items_state) {
         Items_state[$1] = ($2 ? Valid : Null);
      }
   }

   END {
      printEntry();
   }
' infile

Input data :
Code:
entry-id 1

ABC : value
DEF :value
GHI :VALUE

entry-id 2

DEF :value
GHI :VALUE

entry-id 3
ABC : value
DEF :
GHI :VALUE

entry-id 4
ABC : value
DEF :

entry-id 5

ABC : value
DEF :value
GHI :VALUE

Output :
Code:
Ok : entry-id 1
Err: entry-id 2
     Unset: ABC
Err: entry-id 3
     Null : DEF
Err: entry-id 4
     Null : DEF
     Unset: GHI
Ok : entry-id 5

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to log file processing details to database table usnig UNIX shell script?

we are getting files on daily basis.we need to process these files. i need a unix shell script where we can count 1-The no of files processed 2-No of data/record processed for each files. The script should log these details into a database table. If there is any error while file... (3 Replies)
Discussion started by: Atul kumar
3 Replies

2. Shell Programming and Scripting

Parallel processing of SQL through Shell

Hi Friends, I am trying to write a shell which will invoke 3 CTAS (ORACLE create table XXX as select * from YYYY). The approximate time for one CTAS is around 25 mins. So i want to run the CTAS script parallely. My pseudocode is as below. Main script nohup sh CTAS1.sh &... (3 Replies)
Discussion started by: Showdown
3 Replies

3. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

4. Programming

Unix Shell background processing

So I made my own unix shell, but i want to make a background process when using the & appended to the end, so far most of the commands seem to work (except cd, but thats another story) right now here is what I have got. Im thinking maybe I shouldn't be using switch and maybe switch it to... (27 Replies)
Discussion started by: Mercfh
27 Replies

5. Shell Programming and Scripting

File Processing in shell script

i have a file with following type of data abcd : gggggg gggggg ; 1234 gggggg ; 5678 gggggg ; 3434 gggggg ; 6565 gggggg ; 1231 1234 ; vvvv ;Eng=Myfirstname 5678 ; xyzf ;Eng=Mysecondname 3434 ; xyzf ;Eng=Mythirdname 6565 ; xyzf ;Eng=Mysfourthname 1231 ; xyzf ;Eng=Mysfifthname... (7 Replies)
Discussion started by: telangmadhuri
7 Replies

6. Shell Programming and Scripting

Processing files using ksh shell

I need to write a Shell Script to process a huge folder of nearly 20 levels.I have to process each and every file and check which files contain lines like select insert update When I mean line it should take the line till I find a semicolon in that file. I should get a result like this ... (1 Reply)
Discussion started by: 20033716
1 Replies

7. Shell Programming and Scripting

Help with shell script for url processing

Hi, My objective is to make a shell script that, when run, you can input multiple links at once. text is then inserted between the http:// part and the following url. example : http://google.be ==> http://sometext.google.be it would be great if it could then open all the created links (wich... (5 Replies)
Discussion started by: tooster
5 Replies

8. Shell Programming and Scripting

2 file processing script in C shell

I want to use an awk for the following scenario but not sure if it will work or not. I have two input file: F1 and F2 F1 02 05 08 F2 00 01 02 03 04 05 06 07 08 09 10 (1 Reply)
Discussion started by: jclanc8
1 Replies

9. Shell Programming and Scripting

Have a shell script check for a file to exist before processing another file

I have a shell script that runs all the time looking for a certain type of file and then it processes the file through a series of other scripts. The script is watching a directory that has files uploaded to it via SFTP. It already checks the size of the file to make sure that it is not still... (3 Replies)
Discussion started by: heprox
3 Replies
Login or Register to Ask a Question