Read Line and sent as variable for each string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read Line and sent as variable for each string
# 1  
Old 02-20-2011
Read Line and sent as variable for each string

Hi ,

I want to read below output, lets called it output1.txt and each string for every line will be declare as a variables.

This is the input file
Code:
196    server_a    server_unix_2    FW
196    server_b    server_win_1    CD
196    server_c    server_win_2    CD
196    server_bd    server_unix_2    FW
196    server_bd    server_unix_2    CD
196    server_bd    server_unix_2    CD
196    server_bd    server_unix_2    CD

What i want to do is to read every line with each of the string for every line will be given a variable. Eg from line 1: $code is for 196, $client is for server_a , $name for server_unix_2, $time for FW.

This is because later on my script, i will send those variable to be use on another script. I have tried using while and read but all failed.
# 2  
Old 02-20-2011
Have you tried this:
Code:
while read code client name time
do
   # do stuff with variables...
done < output1.txt

# 3  
Old 02-20-2011
Thanks a lot Scrutinizer for the idea, its now working. I tested by sending to my email, below is the script:

Code:
while read code client name sched time
do
#printf "$client\t $code\t $name\t $time\t \n"
echo "$client\t $code\t $name\t $time\n" | mailx -s "Client $client : Name $name failed with code $code at $time" sqew\@abc.com

done < compare1

First i tried to print it, at line with #. Thanks Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

Ksh: Read line parse characters into variable and remove the line if the date is older than 50 days

I have a test file with the following format, It contains the username_date when the user was locked from the database. $ cat lockedusers.txt TEST1_21062016 TEST2_02122015 TEST3_01032016 TEST4_01042016 I'm writing a ksh script and faced with this difficult scenario for my... (11 Replies)
Discussion started by: humble_learner
11 Replies

3. Shell Programming and Scripting

Read line by line and replace string.

Hi, I currently have a problem that I need to read a file line by line. After I read it line by line there are some commands in which I have to change a specific string.(In my case, I have to make a script that changes all the passwords into hash value) Here is a sample input... (3 Replies)
Discussion started by: thebennnn
3 Replies

4. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

5. Shell Programming and Scripting

Deleting double quoted string from a line when line number is variable

I need to remove double quoted strings from specific lines in a file. The specific line numbers are a variable. For example, line 5 of the file contains A B C "string" I want to remove "string". The following sed command works: sed '5 s/\"*\"//' $file If there are multiple... (2 Replies)
Discussion started by: rennatsb
2 Replies

6. Shell Programming and Scripting

How to read a file line by line and store it in a variable to execute a program ?

Hello, I am quite new in shell scripting and I would like to write a little scritp to run a program on some parameters files. all my parameters files are in the same directory, so pick them up with ls *.para >>dirafter that I have a dir file like that: param1.para param2.para etc... I... (2 Replies)
Discussion started by: shadok
2 Replies

7. Shell Programming and Scripting

How read the part of the string into a variable?

Hi, I'm using bash and brand new to shell script. I would like to do the following. I have a string which is "UPDATE=1.0". I would like to read the value "1.0" alone in a variable. i.e the things afer "=" How do I do that? Thanks, (1 Reply)
Discussion started by: scriptfriend
1 Replies

8. Shell Programming and Scripting

read string from file into variable

Hello, I need to read from a file consisting of only one integer and enter that number into variable.can anyone help? the script is written in cshell. thanks. (4 Replies)
Discussion started by: offerbukra
4 Replies

9. Shell Programming and Scripting

read a value from a string/line

I have a file that contains the something like this a=15 b=21.5 c=544 and so on the question is how could I find the line that contains the value of c and store its value on a variable in bash shell?, Thanks in advanced (4 Replies)
Discussion started by: josegr
4 Replies

10. Shell Programming and Scripting

read and assign each character from the string to a variable

How... can I read input by a user character by cahracter. And assign each character from the string to a variable? Any help would be greatly appreciated! Thank you! (1 Reply)
Discussion started by: Tek-E
1 Replies
Login or Register to Ask a Question