Need a helping hand --stuck in starting of this problm.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need a helping hand --stuck in starting of this problm.
# 8  
Old 09-15-2006
Anu thanks a lot , I got a clue to start with.
I have 17 file and each having differnt mandatory column can i generalized the
man_col="1,2,3,4,5,6,10,11" , I mean i want to pass the main_col value from a function and man_col value can be changed in run time like it can be 1,3,6,9,5 or it can be any thing ?

while executing this script in ksh i got
the error
awk: syntax error near line 1
awk: bailing out near line 1

Last edited by jambesh; 09-15-2006 at 02:58 AM..
# 9  
Old 09-15-2006
Also thanks to sayonm , but synom what you guess is right but i could not get what you mention in the last line "save the labour of changing the file name and the no ("25")...."
# 10  
Old 09-15-2006
@jambesh

what i meant was , everytime to check a particular co, u have to change the col name....so i said that to save that labour, a basic script can be written that will do that by its own...somwht the same thing that u mentioned in the last but one reply to anbu

cheers,
sayon

ps: do let us know if u want any other help regarding the automation
# 11  
Old 09-15-2006
Try this jambesh..is that what you are looking for...
you can run this with first argument as filename and from second onwards mandatory column numbers like
scriptname filename.csv 1 2 3 5 7
Code:
# Scriptname filename col1 col2 col3 .....
if [ ! -f "$1" ];then
echo "file $1 does not exist " && exit 1
fi
filename=$1
shift 1
set -A com $*
lineno=1
while read line
do
   i=0
  while [ $i -lt $# ]
  do
  val=`echo $line| cut -d ',' -f${com[$i]}`
  [[ -z "$val" ]] && echo "resend the file line $lineno column ${com[$i]} is null" && exit 1
   i=`expr $i + 1`
  done
lineno=`expr $lineno + 1`
done<$filename

# 12  
Old 09-15-2006
Hi dhruv what is set -A com $* ? and when u write -> while [ $i -lt $# ] what is $# here, is it no of argument ? for what no of argumetn u r making comparison ? please tell me ! bit confused
# 13  
Old 09-15-2006
what this program doing is taking all the column numbers in a array
set -A com $* will set com array with values which you passed in comman line
like sc.sh file.csv 1 4 7 8 then statement
set -A com $* will set com array with com[0]=1,com[1]=4,com[2]=7.......

while [ $i -lt $# ] here $# is number of arguments minus 1 and it will be only no of columns.because after getting filename we used shift 1
filename=$1
shift 1
set -A com $*

need any other clarification?

Last edited by Dhruva; 09-15-2006 at 04:01 AM.. Reason: typo
# 14  
Old 09-15-2006
Hi Dhruv

You are Great boss . Working fine this one .
Can you please give me a clue on the other one tht i post also.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies

2. Shell Programming and Scripting

Helping a Newbie with Shell Homework

Good Evening, i got a homework where i have to list all files in the directory with the name length >=3 and <= 6 and after trying it for 2 days my Prof gave me a bit of code: #!/bin/bash for file in $(ls) do done after that he told me "now you only have to use wc and you got it" but... (1 Reply)
Discussion started by: Mentoss
1 Replies

3. Shell Programming and Scripting

Merge left hand strings mapping to different right hand strings

Hello, I am working on an Urdu to Hindi dictionary which has the following structure: a=b a=c n=d n=q and so on. i.e. Headword separated from gloss by a = I am giving below a live sample بتا=बता بتا=बित्ता بتا=बुत्ता بتان=बतान بتان=बितान بتانا=बिताना I need the following... (3 Replies)
Discussion started by: gimley
3 Replies

4. Shell Programming and Scripting

cut operation is not helping me much

hi, i have a file where I want to extract the the failure count only from the file. JOB_NAME STATE RUN_COUNT FAILURE_COUNT ------------------------------ --------------- ---------- ------------- OFS_BALA_BILLING_IN SCHEDULED 22992 ... (6 Replies)
Discussion started by: gotam
6 Replies

5. Shell Programming and Scripting

Helping in parsing subset of text from a big results file

Hi All, I need some help to effectively parse out a subset of results from a big results file. Below is an example of the text file. Each block that I need to parse starts with "reading sequence file 10.codon" (next block starts with another number) and ends with **p-Value(s)**. I have given... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

6. IP Networking

helping new Linux users remotely ?

I volunteer with a small charity which locally donates refurbished computers to people who normally could not afford their own computer. Most of these computers now have Linux on them. We are in the process of remastering Xubuntu 9.04 to use as our main distro from now on. In the past any time... (3 Replies)
Discussion started by: lagagnon
3 Replies

7. Shell Programming and Scripting

Need a hand. Please?

i have a script in sh. with awk, e.g. want to list all the contents of a subdirectory an a tabular way. ej: outoput directory1 subdirectory1 subdirectory2 subdirectory3 file1 filen file2 filez file2 ... filen+1 ... (1 Reply)
Discussion started by: alexcol
1 Replies
Login or Register to Ask a Question