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.
Jambesh try this one.....here jam1.txt is lookup file and jam2.txt is data file needs to be rearranged.you need to create temp directory in directory where you will run this script.May be this will help...and jamt will be the output file
maxcol=`sed '1q' jam1.txt | awk -F" " '{print NF}'`
col_look=`sed '1q' jam1.txt`
col_seq=`sed '1q' jam2.txt`
set -A look $col_look
set -A seq $col_seq
set -A pos
i=0
while [ $i -lt $maxcol ]
do
j=0
while [ $j -lt $maxcol ]
do
[[ "${look[$i]}" = "${seq[$j]}" ]] && pos[$i]=`expr $j + 1`
j=`expr $j + 1`
done
i=`expr $i + 1`
done
k=0
while [ $k -lt $maxcol ]
do
cut -d ' ' -f${pos[$k]} jam2.txt>temp/tempjam${k}
k=`expr $k + 1`
done
paste temp/tempjam* >jamt
rm -f temp/tempjam*
p.s.
output file columns will be tab delimeter if you want to make it space delimited replace "paste command with
i have checked with the below files and found output file jamt.Please see i had updated my post with paste command.you remove rm command in script and check what is going into tempjam files.
jam1.txt:::
$ cat tempjam5
MANDT SERAIL EQTYP SERSCHA SEREX BSTVP
510 hsgdfs 44 sercha sex1 bst233
510 bg 89 fg 23 98
510 gh 89 we sew mn
sequence is not changing in any of the file ...what is wrong ?
i guess each of the file should produce only one column ..right ?? but it is containing the whole file again surprise !!!!!!!!!!!!!!
yes only one column in each file.problem here is with cut command.
run the below commands on command line one by one and check what is going in files.The field delimeter is single space.
Make sure there is a single space in ' ' (single quotes in below command)
i checked and written this script with assumption that field delimeter is space.
if your file has different delimeter then make the changes.
if delimeter is tab then use cut without -d option.
dhruv,
i have tried with cut -d '\t' and also with cut -d "\t"
it is saying invalid delimeter !! is there any other way out ! my real problem is here boss !
Yogor thanks for replay
i tried with your code as well
but it also giving me error.
awk: syntax error near line 1
awk: bailing out near line 1
paste: cannot open MANDT
---I am completely frustrated with this problem don't understand what to do here now plz assist.
I want to just print the selected column from a file which is delimited by tab and not space .
if you can explain me why
awk -v c1=$f1 -v c2=$f2 'BEGIN{FS=OFS="\t"}{print $c1,$c2}' jam2.txt
this is not working it will be of great help to me
Dhruv,
Thanks a lot for help , thanks for guiding me all through my problem too.
when i left -d option it said invalid range also when i give a tab in between ' ' and trying it give
cut: invalid character in range . i don't understand acttualy if default is tab delimeter why it is not accepting .
also when i am doing cut -f1 jam2.txt > one.txt
all the field of file jam2.txt is copying to one.txt instead of just column one
Real surprise !!!!! for me
please buddy guide me i am completely frustrated and bitting my head on desk for it
Yogor !!!
i have tried with nawk and gawk too nothing happend boss!