generic way - help required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting generic way - help required
# 1  
Old 08-22-2008
generic way - help required

All,

Code:
This is what I did: 

Suppose: 

$ line="23|12|21"

$ eval $(echo "$line" | awk -F'|' '{print "V1="$1";V2="$2";V3="$3}')

$ echo $V1
23

$ echo $V2
12

$ echo $V3
21

Can there be a generic way such that if input line is having more numbers e.g. 

line="1|34|54|23|56|676|21|232"

we assign  each number to variable V1 to V8 as above but not assigning them as I did above(kind of hard coding). Please.

# 2  
Old 08-22-2008
For generic, u need to use like this only.

echo $line | awk '{
as=split($0,TagArr,"|");
for (i=1;i<=as ; i++)
print TagArr[i];
} '
# 3  
Old 08-22-2008
this should work....
Quote:
eval $(echo "$line"|awk 'BEGIN{RS="|"}{print "V"NR"="$0}')

Last edited by vidyadhar85; 08-22-2008 at 11:52 AM..
# 4  
Old 08-22-2008
Quote:
Originally Posted by uwork72
All,

Code:
$ line="23|12|21"

$ eval $(echo "$line" | awk -F'|' '{print "V1="$1";V2="$2";V3="$3}')

Code:
$ line="23|12|21"
eval $(echo "$line" | awk -F'|' '{for(i=1;i<=NF;i++) printf "V%s=%s\n",i,$i}')

and if your shell support, remove UUOecho
Code:
$ line="23|12|21"
eval $(awk -F'|' '{for(i=1;i<=NF;i++) printf "V%s=%s\n",i,$i}' << "$var")


Last edited by danmero; 08-22-2008 at 12:36 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Required help on a Generic File-watcher script

Hi All, Good morning... I have prepared a shell script which will monitor files in a certain folder and if available, SCP it to a destination path. Now the challenge I'm facing is my script is currently SCP-ing to only a single destination path. Wherever different destination path is in... (1 Reply)
Discussion started by: saps19
1 Replies

2. Programming

FORTRAN Generic Operator (^)

I am implementing the cross product of two vectors using ^, however I am getting an error.Not aware how the problem can be resolved. Here is the code Interface Operator (^) Module Procedure vector_cross_product End Interface Operator (^) Contains Function vector_cross_product... (1 Reply)
Discussion started by: kristinu
1 Replies

3. Shell Programming and Scripting

Generic Filewatcher

Hi, I have a requirement wherein i need to have a generic file watcher in place. On presence of a file in a particular directory,the file watcher should identify the related config file and execute the series of the shell scripts mentioned in the config file. eg.Config file a.sh b.sh... (7 Replies)
Discussion started by: dikesm
7 Replies

4. Shell Programming and Scripting

Generic script for Querying a DB

I have a few databases that i need to get some basic output from... so I'll be returning 1 or 2 records from a variety of different databases and the input queries will always differ. What im looking for is a generic script that I can use across of the databases. Theory being i have: ... (2 Replies)
Discussion started by: atelford
2 Replies

5. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

6. UNIX for Advanced & Expert Users

Is aclocal.m4 generic?

can we copy higher version aclocal to our software. Is there any good book for automake,aclocal.m4,configure.sub,configure.guess that explains clearly about how they are related , how to modify them etc Thanks Gopi (1 Reply)
Discussion started by: Gopi Krishna P
1 Replies

7. Solaris

Generic and Solaris Version

I am going to upgrade RAM in V240, I updated the ALOM with version 1.6 and have will update PROM on boot of server, but RAM needs Solaris 9 8/03 or later and from uname -a I get: SunOS name1 5.9 Generic_117171-05 sun4u sparc SUNW,Sun-Fire-V240 not sure what version of Solaris... (3 Replies)
Discussion started by: photon
3 Replies

8. UNIX for Dummies Questions & Answers

GENERIC Kernel

How do I update, change, reconfigure or whatever it is that I have to do, in order to rid the GENERIC label. It just means that it is the basic kernel shipped with the OS right? Im using FBSD 4.5 (2 Replies)
Discussion started by: savage
2 Replies
Login or Register to Ask a Question