manipulation


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers manipulation
# 8  
Old 05-19-2005
Quote:
Originally Posted by vivekshankar
Hi ,
I am really new to unix......loop can accomplish........but my query is how to get 1 row at a time..what command shud i use for it?

Thanks and Regards
Vivek.S
hmmm.....
Are you asking how you can query the DB one row at a time? It depends on your DB. Just put your query 'tool' [sqlplus for Oracle] in the loop from the original posting:

Code:
#!/bin/ksh
while read c1 c2
do
   echo "column1->[${c1}] column2->[${c2}]"

   sqlplus oracleUser/oraclePasswd@oracleSID <<EOF
       select ${c1} from table where something = ${cl2}
EOF
done < myTableFile

you'll have to work out the details - searching the FAQ archieves might help.
# 9  
Old 05-19-2005
hi,
i am not fetching it from db

i have all these ine falt file....its exactly liek this

field1 field2
name1 name2
oops1 oop2

THESE ARE ALL STORED IN FLAT FILE NOT DB

i need to get 1 row at a time.......

how can i do this?

THANKS
vivek.s
# 10  
Old 05-19-2005
this?

Code:
#!/bin/ksh
while read c1 c2
do
   #echo "column1->[${c1}] column2->[${c2}]"
   echo "select ${c1} from table where something = ${cl2}"
done < myTableFile

# 11  
Old 05-19-2005
Quote:
Originally Posted by vivekshankar
No i am trying to read from flat file only..........
Your requirement isn't really clear and you examples are maybe misleading. Perhaps you are trying to simulate a database "select" against a UNIX flat file.

Does this describe your requirement? Read from a flat file using syntax similar to "select column1 from table where something = column2"

If this is the case, you aren't going to get what you want. The scripting constructs do not lend themselves to SQL like commands. If you are wanting to use SQL like constructs then you still need some kind of DBMS query tool (like sqlplus) that lets you read from flat files rather than a database.

Thomas
# 12  
Old 05-19-2005
yes.........maybe i ahve confused everyone !sorry!

well this is my requirement!please forget all about databses.......i have no database now........i have a flat file which has two columns....how can read 1st row from the file......then 2nd row from the file and so on till end is reached?

hope this is bit more clear


USING THIS WILL I BE ABLE TO DO IT?


while read c1 c2
do
#echo "column1->[${c1}] column2->[${c2}]"
echo "select ${c1} from table where something = ${cl2}"
done < myTableFile


how will unix recognize c1 and c2?



THANKS A LOT FOR UR HELP GUYS!

Regards
vivek.s
# 13  
Old 05-19-2005
Quote:
Originally Posted by vivekshankar
yes.........maybe i ahve confused everyone !sorry!

well this is my requirement!please forget all about databses.......i have no database now........i have a flat file which has two columns....how can read 1st row from the file......then 2nd row from the file and so on till end is reached?

hope this is bit more clear


USING THIS WILL I BE ABLE TO DO IT?
YES

Quote:
Originally Posted by vivekshankar
while read c1 c2
do
#echo "column1->[${c1}] column2->[${c2}]"
echo "select ${c1} from table where something = ${cl2}"
done < myTableFile


how will unix recognize c1 and c2?
Shell [ != unix] will read each record//line from file myTableFile and "split" it into 2 variables [c1 and c2] based on the value of the IFS variable [set by default to " " - this value can be reset to whatever field separator your data file uses].

The values of the read columns can be used with in the "while" loop referenced by ${c1} and ${c2}.

Is that clearER?

I suggest you read the 'man' pages for whatever shell you're using and/or browse through some this site's FAQ pages.

Quote:
Originally Posted by vivekshankar
THANKS A LOT FOR UR HELP GUYS!

Regards
vivek.s
# 14  
Old 05-19-2005
THANKS A LOT

Regards
vivek.s
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File manipulation

Hi, I want to update the file with a value at a particular position $cat test.txt COL1=TEST COL2= COL3=AADSDFSDFDSFDFDF I want to update the file with a value for COL2. After update, the file should be like this $cat test.txt COL1=TEST COL2=1 COL3=AADSDFSDFDSFDFDF here 1... (9 Replies)
Discussion started by: vedanta
9 Replies

2. Shell Programming and Scripting

String manipulation

Hello Could you help with small script: How to split string X1 into 3 string String X1 can have 1 or many strings X1='A1:B1:C1:D1:A2:B2:C2:D2:A3:B3:C3:D3' This is output which I want to have: Z1='A1:B1:C1:D1' Z2='A2:B2:C2:D2' Z3='A3:B3:C3:D3' (5 Replies)
Discussion started by: vikus
5 Replies

3. Shell Programming and Scripting

String manipulation

I want to do the next "I don't want to go school because I'm sick today." I want to join these two line but only when the first line is not more than 20 characters and ended whit nothing or a comma and the second line not more than 15. The 20 and the 15 can be change in the script. I know... (10 Replies)
Discussion started by: thailand
10 Replies

4. UNIX for Dummies Questions & Answers

Manipulation of a list

I have a list of file names, such as below n02-z30-dsr65-terr0.50-dc0.002-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.006-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.010-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.004-8x6drw-csq.msf n02-z30-dsr65-terr0.50-dc0.008-8x6drw-csq.msf I want to... (11 Replies)
Discussion started by: kristinu
11 Replies

5. UNIX for Dummies Questions & Answers

Text manipulation help

Hello unix.com users, I have a ip file (line-by-line). How can I delete the ips that keep repeating by mark XXX.XXX.XXX.* ... I want to erase only the lines that keep repeating more than 2 times. Example: 1.2.3.1 1.2.3.2 1.2.3.3 I want to erase all ips blocks that are repeating by C... (1 Reply)
Discussion started by: galford
1 Replies

6. UNIX for Dummies Questions & Answers

Text Manipulation Help

Hello Unix.com, I have a text in format: john sara lee How can I make it: john:john john:john1 john:john12 john:john123 sara:sara sara:sara12 sara:sara123 and so on (2 Replies)
Discussion started by: galford
2 Replies

7. Shell Programming and Scripting

PATH manipulation

I have a requirement like this: I have modified versions of certain internal/external commands that I am putting into some directory say /mydir. All the users will go an authentication check once they log in and based on the outcome there are two possibilities: 1. User passes... (12 Replies)
Discussion started by: ramesh_samane
12 Replies

8. Shell Programming and Scripting

$0 manipulation in awk

OK, so if $0 represent the entire record... can I change $2 and will that be reflected back in $0? I think the following answers that YES, it does work. But is there anything I should be thinking about prior to doing this? What I am actually doing is part of 5 pages of scripting and awk... (1 Reply)
Discussion started by: joeyg
1 Replies

9. Shell Programming and Scripting

string manipulation

Hi all, see i have a script that takes few arguments. first one is command we do on file, next is file (mostly txt file with lot of data) third is destination where we do something with data in file. Since im new in scripting, and im learning as i go, i need some hint how to manipulate that... (3 Replies)
Discussion started by: ajemrunner
3 Replies

10. Shell Programming and Scripting

File Manipulation...

Hi Freinds, :b: i have a flat file with below format... 1234,Hary,102.55 4567,Maria,250.40 78942,suzan,261.60 48965,Harun,179.32 so I need a script that can get me as below format... 1) 1234,Hary,103 2) 4567,Maria,250 3) 78942,suzan,262 4) 48965,Harun,179 Which means, it... (6 Replies)
Discussion started by: malcomex999
6 Replies
Login or Register to Ask a Question