![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can't figure out what field separator to use in awk.... | thom.mattson | UNIX for Dummies Questions & Answers | 3 | 06-10-2009 03:42 AM |
| How to set Field Separator for TCLSH??? :S | laptop87 | Shell Programming and Scripting | 2 | 12-19-2008 11:07 AM |
| Field separator Ques. | yahyaaa | Shell Programming and Scripting | 6 | 09-16-2008 02:54 PM |
| Change field separator of grep from : to space | Jenny.palmy | UNIX for Dummies Questions & Answers | 2 | 06-09-2008 04:16 AM |
| How do I specify tab as field separator for sort? | SSteve | UNIX for Dummies Questions & Answers | 8 | 04-26-2005 05:39 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
dynamically change awk Field Separator FS
Hi All,
I was wondering if anyone knew how to dynamically change the FS in awk to accept vairiable containing a field separator. the current code is as below and does not work when i introduce the dynamic FS change :-( validate_source_file() { source_file=$1 datetimestamp=`date +"%Y%m%d%H%M%S"` invalid_file=$2_$datetimestamp.dat field_count=$3 file_delimeter=$4 #awk 'BEGIN{ FS="|"; } { awk 'BEGIN{ FS=file_delimeter; } { if ( NF != field_count ) { invalid_rec_count+=1 ; # # print the header for the bad file once....then start printing the invalid records to the same file... # print $0 > invalid_file ; } else { valid_rec_count+=1 ; } } END { printf "%-10s\t\n%-10s\t\n%-10s\t\n","Total Lines Read ["NR"]","Valid Records Found ["valid_rec_count"]","Invalid Records Found ["invalid_rec_count"]" ; if (invalid_rec_count>1) { print " " print "Please refer to file "invalid_file" for full invalid record set." } } ' invalid_file="$invalid_file" field_count="$field_count" file_delimiter="$file_delimeter" $source_file } so when I call it i would want to pass a 4th parameter like: validate_source_file "$filenamedir" "$source_tabin_name" "$field_count" "," or validate_source_file "$filenamedir" "$source_tabin_name" "$field_count" "|" Any ideas appreciated! Regards Satnam |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|