Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Data Handling in Script

This is a discussion on Data Handling in Script within the Shell Programming forums, part of the Operating Systems category; I have a text file which has millions of data of employees present in it. I have my last field ...

  1. #1
    Rahulbatra is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    124

    Data Handling in Script

    I have a text file which has millions of data of employees present in it. I have my last field of these employees as my userid which is currently left as NULL for all records in the text file. I want to give write a script so that all the data’s present in the text file is appended at the last with my name. Kindly suggest a way for achieving this.


  2. #2
    Hélio de Araújo Estrêla is offline Junior Member Array
    Join Date
    Mar 2011
    Location
    São Caetano do Sul, Brazil
    Answers
    2
    Try, it is awk code:

    Code:
    awk -v my_userid="your_userid" -v my_name="your name"  '{ 
    
       vrec=$0;
       vstart = length(vrec) - ( length(my_userid) * 2 );
       if ( vstart < 0 ) vstart = 1;
    
       vtmp_string=substr(vrec, vstart);
    
       if ( index(vtmp_string, my_userid) > 0 ) { 
        
         print vrec my_name
       
       }
       else  {
        print vrec
       }  
      
    }' your_text_file.txt


    Last edited by admin; 03-06-2011 at 06:31 AM.

Latest Article

Network Security Risk Assessment and Measurement

Read More...