
- Forum
- Operating Systems
- Shell Programming
- Data Handling in Script
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 ...
-
05-17-2007, 05:16 PM #1
- 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.
-
03-05-2011, 08:06 PM #2
- 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.

Reply With Quote





