help Needed for READ command.....


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers help Needed for READ command.....
# 1  
Old 08-14-2006
CPU & Memory help Needed for READ command.....

Hi UNIX BONDS,
My requirement is that i want to use READ as
while read a x y z
do
some logic
done < dummy_file.txt

But the requirement is that the number of columns in the file dummy_file.txt is not fixed.
So "while read a x y z" may work fine if there are four columns, but how do i decalre variables when the columns may keep on varying.

Basically i dont want to hard code the number of columns as done above...

Thanx in advance......
Regards,
rahul26 Smilie
# 2  
Old 08-14-2006
Computer

It's not a solution Rahul but a hint. I remeber telling you about NR of awk. You can use this do create a dynamic line for your while statement. Just try it yourself, it will help you in learning concepts.

regards
Apoorva Kumar
# 3  
Old 08-14-2006
will something like this help you to proceed !!!

Code:
>cat dump.dat

abcde 123
abcde 234 567
abcde

Code:
>awk '{ for(x=1; x<= NF; x++) { print x " : " $x } }' dump.dat

1 : abcde
2 : 123
1 : abcde
2 : 234
3 : 567
1 : abcde
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command needed

Hi, I have the date as 20130101 and i need it to rephrased to 2013-01-01. Any command which can do this. (5 Replies)
Discussion started by: ATWC
5 Replies

2. Shell Programming and Scripting

Read from file and execute the read command

Hi, I am facing issues with the below: I have a lookup file say lookup.lkp.This lookup.lkp file contains strings delimited by comma(,). Now i want to read this command from file and execute it. So my code below is : Contents in the lookup.lkp file is : c_e,m,a,`cd $BOX | ls cef_*|tail... (7 Replies)
Discussion started by: vital_parsley
7 Replies

3. Shell Programming and Scripting

Needed shell script to read txt file and do some modification

Hi ...programmers... I need a shell script to perform some specific task.. my txt file looks like this netcdf new { dimensions: XAX1_11 = 11 ; variables: double XAX1_11(XAX1_11) ; XAX1_11:point_spacing = "even" ; XAX1_11:axis = "X" ; float DEPTH(XAX1_11) ;... (19 Replies)
Discussion started by: Akshay Hegde
19 Replies

4. UNIX for Dummies Questions & Answers

dd command help needed.

Hi I m creating a file which will serve as a virtual harddisk . I m using following command to create a file. #dd if=/dev/zero of=/tmp/Sample.dat bs=1M count=1024 I have following doubts regarding the operation. 1) In above example i m creating a file with byte size of 1M .However in... (1 Reply)
Discussion started by: pinga123
1 Replies

5. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

6. Shell Programming and Scripting

Shell Script Needed to Read a text from a list files

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. I need this script as I m planning to put this for a system health check. Please assist me. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the... (4 Replies)
Discussion started by: kashriram
4 Replies

7. Shell Programming and Scripting

URGENT: Script/Function needed to read text property files in block wise

Hi, Iam in a need for a script/function in KSH where I want to read a text file (property file) in block by block. Here is the example: Heading Name Descripton Block Block1 Value1 Description Property Name Value Property Name Value Property Name Value Property Name Value Property Name... (7 Replies)
Discussion started by: ysreenivas
7 Replies

8. Shell Programming and Scripting

SED and Read Help Needed

Not sure why my sed script is not working..need extra eyes..Any help would be aprreciated. I want to add this line into the 1rst line of the $EJECT FILE sed '/">>>>>>>>>>>>> TAPES TO BE EJECTED /a\<<<<<<<<<<<<<<<<<"'> $EJECT This is the error message I get: + sed /">>>>>>>>>>>>> TAPES TO... (1 Reply)
Discussion started by: gzs553
1 Replies

9. UNIX for Dummies Questions & Answers

Help needed with find command

Hi Guys, Can someone help with this. I have to find out a file name which calls the following sql script "abhishek_to_sdw.sql". In other words it contains a pattern like "abhishek_to_sdw.sql". I have found out using "find" command that the file abhishek_to_sdw.sql is existing on the... (4 Replies)
Discussion started by: max29583
4 Replies

10. Shell Programming and Scripting

help needed in ls command

Hi all, i need to write an ls command which will pick up ind_01.txt/pak_01.txt from ind_01.txt pak_01.txt usa_01.txt files in a directory.. i wrote a ls command by storing ind and pak in 2 variables and listing it. Its working fine. But the pattern to be matched should be sent in... (1 Reply)
Discussion started by: anju
1 Replies
Login or Register to Ask a Question