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
break out of 'if' finalight Shell Programming and Scripting 7 11-19-2008 03:54 PM
how to read record by record from a file in unix raoscb UNIX for Dummies Questions & Answers 1 05-16-2008 06:30 AM
Script to search a bad record in a file then put the record in the bad file shilendrajadon Shell Programming and Scripting 2 12-28-2007 10:02 AM
Script to search a bad record in a file then put the record in the bad file shilendrajadon UNIX for Advanced & Expert Users 1 12-28-2007 10:00 AM
splitting a record and adding a record to a file rsolap Shell Programming and Scripting 1 08-13-2007 01:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-01-2007
lyonsd lyonsd is offline
Registered User
  
 

Join Date: Jan 2005
Posts: 35
Help using IFS to break up a record (ksh)

I have a program that produces output similar to this:

Code:
 16010001pe3m_313101.ver
 16010001pe3m_313101.ver

 16010001pe4m_0
 16010001pe4m_0

 16010001pe4m_1
 16010001pe4m_1

 16010001pe4m_313101.ver
 16010001pe4m_313101.ver

 group_defs.txt
 Group Definition File
I have a ksh script where I am trying to get it to print like this:

Code:
16010001pe3m_313101.ver 16010001pe3m_313101.ver
16010001pe4m_0              16010001pe4m_0
16010001pe4m_1              16010001pe4m_1
16010001pe4m_313101.ver 16010001pe4m_313101.ver
group_defs.txt                   Group Definition File
Here is what the code looks like:

Code:
	typeset -L80 relative_path
	typeset -L80 description
	typeset -i count=0
	OFS=IFS
	IFS='
'
	for i in $(program)
	do
		print $i
	done
So I need to get two lines into two separate variables, and I need iterate through the loop when a blank line is encountered.

I've tried using...

Code:
IFS='
'
while read var1 var2
do
  print $var1 $var2
done < $(program)
But that doesn't work either.

How do you set IFS to a blank line?

Suggestions welcome.

Thanks.
  #2 (permalink)  
Old 11-01-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
One way, assuming the blank lines are just a carriage return:
Code:
awk '{              
        if( len($0) )
             { print $0 }
        else
              {printf("%s ", $0) }
        END{ print }
       }' filename > newfilename
  #3 (permalink)  
Old 11-01-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
nawk -f lyon.awk myFile.txt
lyon.awk:
Code:
BEGIN {
  FS=RS=""
}
{
  for(i=1; i<= NF; i++)
    printf("%-80s%s", $i, (i==NF) ? "\n" : "")
}
Sponsored Links
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 04:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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