Splitting the records using counter of input file

Discussion in 'Unix' started by bashamsc, Feb 4, 2012.

  1. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    I am having a File format as mentioned below

    Below is the code to handle above scenario

    Code:
    while read line    
    do    
    	emp_id=`echo $line | awk -F'|' '{print $1}'`
    	name=`echo $line | awk -F'|' '{print $2}'`
    
    	counter=`echo $line | awk -F'|' '{print $3}'`
    	counter1=4 
    
     	while [[ $counter -gt 0 ]]  
    	do
    	  								
    		language=`echo $line |cut -f$counter1 -d"|"`
    									
    		counter1=`expr $counter1 + 1`
    		counter=`expr $counter - 1`
    									
    		echo $emp_id'|'$name'|'$language>>output.txt
    	done
    
    
    done <input.txt
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice