The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Storing commands in $variables. Paulw0t Shell Programming and Scripting 7 08-08-2008 02:42 PM
Storing data of files Fr0z3n999 UNIX for Dummies Questions & Answers 1 12-09-2006 06:47 PM
first row data into variables u263066 Shell Programming and Scripting 1 08-14-2006 04:54 AM
Splitting data file ctcuser Shell Programming and Scripting 4 01-08-2005 06:04 AM
awk - storing data in variables 2nilotpal Shell Programming and Scripting 7 04-16-2004 02:32 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 138
Arrow 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
Reply With Quote
Forum Sponsor
  #2  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 138
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
Reply With Quote
  #3  
Old 01-31-2008
Registered User
 

Join Date: Apr 2007
Location: Kolkata
Posts: 81
Thumbs up

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
Reply With Quote
  #4  
Old 01-31-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 138
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
Reply With Quote
  #5  
Old 02-01-2008
Registered User
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 138
Quote:
Originally Posted by jisha View Post
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
Reply With Quote
  #6  
Old 02-01-2008
Registered User
 

Join Date: Apr 2007
Location: Kolkata
Posts: 81
Thumbs up

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
Reply With Quote
  #7  
Old 02-15-2008
Registered User
 

Join Date: Feb 2008
Posts: 13
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?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:39 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0