![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| print line before column 1 transitions | ajp7701 | Shell Programming and Scripting | 2 | 04-17-2008 11:05 PM |
| how to read the column and print the values under that column | gemini106 | Shell Programming and Scripting | 6 | 03-28-2008 07:05 AM |
| Print row if value in column 1 is the first occurence | Raynon | Shell Programming and Scripting | 7 | 03-18-2008 02:31 AM |
| to print column using awk | cdfd123 | Shell Programming and Scripting | 2 | 07-26-2007 01:15 PM |
| Print last 4 columns (variable column #) | Da_Duck | UNIX for Dummies Questions & Answers | 19 | 02-27-2004 10:33 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Quote:
awk's InputFieldSeparator variable is 'FS'. shell's InputFieldSeparator variable is 'IFS'. |
|
|||||
|
vgersh,
I tried with this code but it is saying -- f1=${ccseq[0]};f2=${ccseq[1]};f3=${ccseq[2]};f4=${ccseq[3]};f5=${ccseq[4]};f6=${ccseq[5]} awk -v c1=$f1 -v c2=$f2 -v c3=$f3 -v c4=$f4 -v c5=$f5 -v c6=$f6 'BEGIN{OFS=FS="\t"} {print $c1,$c2,$c3,$c4,$c5,$c6}' ${fname} awk: syntax error near line 1 awk: bailing out near line 1 can you please help me out ! I want the column value could be anything between 1-6 so i have tried to assign c=$f1 ,c2=$f2,....here f1 ,f2 ,....will be generating the proper column sequence between 1 to 6 and passed to awk to print ..but i am failed to do so. I am using SunOS. Last edited by jambesh; 09-18-2006 at 01:29 AM.. |
|
|||||
|
the fixed look up column sequence string is
"MANDT SERAIL SERSCHA SEREX EQTYP BSTVP " Shell Script i had written that actually determine the correct sequence for an input file. Script: ####Use lookup_data.sh client_file########### fname=$1 set -A lookup_string MANDT SERAIL SERSCHA SEREX EQTYP BSTVP set -A cseq set -A Headr `head -1 ${fname}` echo ${Headr[*]} i=0 while [ $i -lt ${#lookup_string[@]} ] do j=0 while [ $j -lt ${#Headr[@]} ] do if [ "${lookup_string[$i]}" = "${Headr[$j]}" ] then echo "look up and file column equal at $j " cseq[$i]=$j break fi ((j=j+1)) done ((i=i+1)) done i=0 while [ $i -lt ${#cseq[@]} ] do ccseq[$i]=`expr ${cseq[$i]} + 1` echo " ${ccseq[$i]} : \c " ((i=i+1)) done echo f1=${ccseq[0]};f2=${ccseq[1]};f3=${ccseq[2]};f4=${ccseq[3]};f5=${ccseq[4]};f6=${ccseq[5]} awk -v c1=$f1 -v c2=$f2 -v c3=$f3 -v c4=$f4 -v c5=$f5 -v c6=$f6 'BEGIN{OFS=FS="\t"} {print $c1,$c2,$c3,$c4,$c5,$c6}' ${fname} Input file : cat client_data.txt MANDT SERAIL EQTYP SERSCHA SEREX BSTVP 510 hsgdfs 44 sercha sex1 bst233 510 bg 89 fg 23 98 510 gh 89 we sew mn running the script as $ script_name.sh client_data.txt giving correct sequence but unable to print in that sequence ... please assist can any body tell me why red colored two line are not working ?????? Last edited by jambesh; 09-18-2006 at 03:10 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|