Splitting the data and storing it into 2 variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Splitting the data and storing it into 2 variables
# 1  
Old 02-01-2008
CPU & Memory Splitting the data and storing it into 2 variables

Hi,

I have a file in the given format:

|aaa |hhh |fat hat chat |make sure

I need to get store in a variable,say 'error' the value of the string 'fat hat chat'

In short,
echo $error should give the result
fat hat chat

Is this possible using awk?

Also, can this be split.For example, I have to store the value of the string (fat hat chat) in to two variables.Say, error1 and error2 (Given field width is predefined)
i.e
error1=fat ha
error2=h chat



Thanks in advance
Js
# 2  
Old 02-01-2008
I have got the answer for my first question:

sed '1q' 1psql.out | awk -F"|" '{print $3}' ( I found this from the forum it self)

But can some one help me with teh second part???

Thanks in advance
Js
# 3  
Old 02-01-2008
MySQL

Dear jisha,

try this

to get the value of "error=hat fat chat", use this

awk -F'|' '{print $3}' filename

to split a value,
try this

split($3,a,<seperator of the value>)

gud luk

Regards,
Pankaj
# 4  
Old 02-01-2008
Thanks for ur time Pankaj.
Can u please explain me what the 'a' and separator of the value stands for?
I searched in the man page .. But didnt understand any thing ..

Regards,
Js
# 5  
Old 02-01-2008
Quote:
Originally Posted by jisha
Hi,

I have a file in the given format:

|aaa |hhh |fat hat chat |make sure

I need to get store in a variable,say 'error' the value of the string 'fat hat chat'

In short,
echo $error should give the result
fat hat chat

Is this possible using awk?

Also, can this be split.For example, I have to store the value of the string (fat hat chat) in to two variables.Say, error1 and error2 (Given field width is predefined)
i.e
error1=fat ha
error2=h chat



Thanks in advance
Js


Can any one tell me the solution for the same question when the given file has fields not separated by the | ???

Thanks in advance
Js
# 6  
Old 02-01-2008
MySQL

Dear Jisha,

split($3,a,<seperator of the value>)

here a is the array variable. u can use error instead of a
then print like this

print a[1]
print a[2]

u'll cum to know the thing

Regards,
Pankaj
# 7  
Old 02-15-2008
Question how to use split

hi there! (i'm at SunOS 5.9)

i'm trying to split a string with *split*, but i can't.

for example:

in shell i do:

$ string='hi go bye'
$ then i try: awk 'split($string, strings, " ")'
(and a get the following)
$ awk: syntax error near line 1
$ awk: illegal statement near line 1

i've tried a lot of choices, with files and more, and i can't get what's going on.

how can i make it work?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Storing the SQL results in array variables

Requirement 1) I need to execute 15 SQL queries in oracle through linux script. All these query results needs to be stored in array variables. Requirement 2) And these 15 queries needs to be executed in parallel. Requirement 3) Once all the queries executed then the shell script should... (3 Replies)
Discussion started by: Niranjancse
3 Replies

2. Programming

Splitting string and storing in int

I have a string containing 2 integers separated by /, for example 12/8 or 8/6 am want to store the numbers in two integers. (3 Replies)
Discussion started by: kristinu
3 Replies

3. Shell Programming and Scripting

perl : splitting the data into 2 different variables

I have a perl variable which contains the below value. $var1 = "2% / 51%" Now I would like to split the data into 2 different variables. For example $part1 = 2 $part2 = 51 Could anyone please help me in this regard ? Regards, GS (4 Replies)
Discussion started by: giridhar276
4 Replies

4. Shell Programming and Scripting

Storing outputs into variables

I need to know how to store output from one command so that it can initiate another command. chktraf -s | cut -c1-4 output would look like 321 142 256 342 123 Then if the value of the output = 0, then initiate next command. if then for xx in 01 02 03 04 05 06 07 08 09 10 do ... (4 Replies)
Discussion started by: Shaun74
4 Replies

5. UNIX for Dummies Questions & Answers

Storing variables and using them..

Hello Apologies for not having the most accurate of thread titles.. I'm using IBM Rational Synergy CM software. I use the Synergy commands in tandem with Unix commands. I have a directory containing source code objects: bash-3.00$ ccm ls *.fmb *.rdf *.pll *.mmb cre_applications.fmb-1... (1 Reply)
Discussion started by: Glyn_Mo
1 Replies

6. Shell Programming and Scripting

To read data word by word from given file & storing in variables

File having data in following format : file name : file.txt -------------------- 111111;name1 222222;name2 333333;name3 I want to read this file so that I can split these into two paramaters i.e. 111111 & name1 into two different variables(say value1 & value2). i.e val1=11111 &... (2 Replies)
Discussion started by: sjoshi98
2 Replies

7. Shell Programming and Scripting

Storing awk output into variables

Hi all, Currently, i have a log file seperated by 'tab' and each record starting with a new line. i managed to retrieve the column that i'm interested in. (source_ip_address: xxx.xxx.xxx.xxx). example of awk output: '{ print $43 }' assuming the field is at column 43. 10.10.10.10... (4 Replies)
Discussion started by: faelric
4 Replies

8. Shell Programming and Scripting

Storing commands in $variables.

Hi I'm trying to store commands in variables... like so.. # lastcmd=" $t1 | $t2 | $t3 | $t4 | sort | uniq" t1="sed -e 's/http:/<li><a href=\"http:/'" t2="sed -e 's/http:.*/&\">&<\/a>Web Link<br>/'" t3="sed -e 's/.*. mailto:/<li><a href=\"mailto:/'" t4="sed -e... (7 Replies)
Discussion started by: Paulw0t
7 Replies

9. Shell Programming and Scripting

storing variables in array.Please help

Hi All, I need some help with arrays. I need to take input from the user for hostname, username and password until he enters .(dot) or any other character and store the values in the variable array. I would further connect to the hostname using username and passwd and copy files from server to... (7 Replies)
Discussion started by: nua7
7 Replies

10. Shell Programming and Scripting

awk - storing data in variables

In AWK script how do I store data in variables for later use. I have a multiline input and I do not want to print the data read on the console Thnaks in advance. Nilotpal. (7 Replies)
Discussion started by: 2nilotpal
7 Replies
Login or Register to Ask a Question