Making Variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making Variables
# 1  
Old 04-28-2010
Making Variables

Dear Friends,
Here I need your help once again.

I have a flat file with pipe de-limited format

e.g. 12345|1234567890|0|0|0|
(Total 5 values)

I want to take all non 0 ("Zero") values in variables named as anu1, anu2, anu3, anu4 and anu5.
Is it possible?

Please guide me.
Thank you in advance.
Anushree
# 2  
Old 04-28-2010
what about the other rows?
also depends how you want to use the variables.
one way:

Code:
while IFS="|" read a1 a2 a3 a4 a5
do
 echo $a1,$a2,$a3,$a4,$a5
done < file

you can have checks for non-zero values as per your requirement.
# 3  
Old 04-28-2010
Hi,

Try this,

Code:
#!/usr/bin/perl

while (<>) {
chomp;
@array = split /\|/;
for ($i=0;$i<$#array;$i++)
{
if ( $array[$i] eq 0 ) { print " $array[$i] : - Zero\n" ;}
else { print "$array[$i] : - Non Zero \n"; }
}
}

Code:
perl script.pl input_filename

# 4  
Old 04-28-2010
Thanks Anchal, and Thanks Pravin for the prompt responce.
I have tried Anchal's solution which worked fine only prob is it is not ignoring "Zeros", but its fine I think i can now manage those zeros.

Thank you again for both the solutions.
Take care, God bless you
Anushree
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

2. UNIX for Dummies Questions & Answers

How to pass variables into anothother variables?

Below are three variables, which I want to pass into variable RESULT1 username1=userid poihostname1=dellsys.com port1=8080 How can I pass these variables into below code... RESULT1=$((ssh -n username1@poihostname1 time /usr/sfw/bin/wget --user=sam --password=123 -O /dev/null -q... (4 Replies)
Discussion started by: manohar2013
4 Replies

3. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

4. Shell Programming and Scripting

BASH arrays and variables of variables in C++

Sometimes it is handy to protect long scripts in C++. The following syntax works fine for simple commands: #define SHELLSCRIPT1 "\ #/bin/bash \n\ echo \"hello\" \n\ " int main () { cout <<system(SHELLSCRIPT1); return 0; } Unfortunately for there are problems for: 1d arrays:... (10 Replies)
Discussion started by: frad
10 Replies

5. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

6. UNIX for Advanced & Expert Users

Regarding help for making own OS

Dear Fellow, I want to make my own OS, Kindly suggest from where i should start. please help me out. (2 Replies)
Discussion started by: zaigham_tt
2 Replies

7. Shell Programming and Scripting

[PHP] Need help with making variables Global

I have made a script that requires another php script for functions. I need a way so that the required script can read and write the main script's variables. Best Regards, John Wei ---------- Post updated at 08:54 AM ---------- Previous update was at 08:40 AM ---------- Sorry Guys, EDIT: my... (1 Reply)
Discussion started by: johntzwei
1 Replies

8. Shell Programming and Scripting

Making 256 files with variables

Hi, I am really sorry for posting a newbie question here, but I do not have time to start learning shell scripting at the very moment. My question is how can I write a script what takes a file with a variable number, changes the variable number to a new number and saves the file as a new... (5 Replies)
Discussion started by: mario8eren
5 Replies

9. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies
Login or Register to Ask a Question