1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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