The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 05:42 PM
Storing data of files Fr0z3n999 UNIX for Dummies Questions & Answers 1 12-09-2006 09:47 PM
first row data into variables u263066 Shell Programming and Scripting 1 08-14-2006 07:54 AM
Splitting data file ctcuser Shell Programming and Scripting 4 01-08-2005 09:04 AM
awk - storing data in variables 2nilotpal Shell Programming and Scripting 7 04-16-2004 05:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-01-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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
  #2 (permalink)  
Old 02-01-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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 (permalink)  
Old 02-01-2008
panknil panknil is offline
Registered User
  
 

Join Date: Apr 2007
Location: Kolkata
Posts: 83
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
  #4 (permalink)  
Old 02-01-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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 (permalink)  
Old 02-01-2008
jisha jisha is offline
Registered User
  
 

Join Date: Jan 2008
Location: Bangalore,India
Posts: 144
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
  #6 (permalink)  
Old 02-01-2008
panknil panknil is offline
Registered User
  
 

Join Date: Apr 2007
Location: Kolkata
Posts: 83
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
  #7 (permalink)  
Old 02-15-2008
viko viko is offline
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?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0