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
Accessing variables of one shell script in another shell script rsendhilmani Shell Programming and Scripting 2 03-17-2009 01:17 AM
invoking a shell script inside cgi shell script smriti_shridhar Shell Programming and Scripting 2 07-09-2008 01:50 AM
Accessing variables of one shell script in another shell script looza Shell Programming and Scripting 2 06-30-2008 07:13 PM
How to pass a parameter from one Shell-script to another Shell-script subodhbansal Shell Programming and Scripting 2 09-22-2007 05:19 AM
How to Run a shell script from Perl script in Parent shell? hifake Shell Programming and Scripting 16 08-28-2007 08:42 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
Netherxx Netherxx is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 2
Need help with shell script

All,

I need some help with a shell script that is supposed to look in a text file. In that text file, fields are separated between accolades (starting with { and ending with }).

I want to loop through the fields in the file, and look into each field to find a specific value.

I have found that AWK has a field separator function, but this when i fill in the Field separater "{" it gives me the wrong result.
The text file looks like this:

Code:
 
{{This is the first field}{This is the second field}{This is the third 
field}{Fourth}{Fifth}}

Last edited by zaxxon; 3 Weeks Ago at 05:24 AM.. Reason: use code tags please
  #2 (permalink)  
Old 3 Weeks Ago
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
You can use braces as fieldseparators, and access the first field as $3, the second field as $5 and so forth. Something like:

Code:
awk -F "[{}]" '{print $3,$5,$7,$9,$11}' RS= textfile
  #3 (permalink)  
Old 3 Weeks Ago
Netherxx Netherxx is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 2
Reply

Thanks !

How can i loop these records and compare the values of those fields?

i assume that i need to have an if statement embedded in the awk clause, but haven't got a clue where to begin.
  #4 (permalink)  
Old 3 Weeks Ago
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,294
Something like this:

Code:
awk -F "[{}]" '{
  if($3==".."){...} # If field 1 == "..." do something
  if($5==".."){...} # If field 2 == "..." do something
  .
  .
}' RS= textfile
Have a read of some awk tutorials here:

Unix Tutorials/Programming Tutorials/Shell Scripting Tutorials
Reply

Bookmarks

Tags
awk, field separator, shell

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 08:16 AM.


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