Help using IFS to break up a record (ksh)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help using IFS to break up a record (ksh)
# 1  
Old 11-01-2007
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  
Old 11-01-2007
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  
Old 11-01-2007
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" : "")
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Line break in sqlplus output through ksh script

Hi, I am new to shell script programming. I have written a ksh script to run the sql File placed in server directory and spool the output in destination directory. Below Command: $ORACLE_HOME/bin/sqlplus -s $ora_uid @$sqlfile_loc$testquery.sql > $opfiledirectory It is generating the output... (6 Replies)
Discussion started by: Sumit Arora
6 Replies

2. Shell Programming and Scripting

Break on record with multiple with userid

I'm using the unix terminal in Mac osx yosemite. I have a file 1;2015p;2014r;2013r;2013p 2;2013p;2013r;2012g 3;2013g 4;2015g;2014g;2013r;2012s;2011s The first column is the userid, the second column is each event. I'd like a separate record for each event. 1 2015p 1 2014r 1 ... (5 Replies)
Discussion started by: Nataliemf
5 Replies

3. Shell Programming and Scripting

ksh while read loop breaks after one record - AIX

#!/bin/ksh for SRV in imawasp01 \ imawasp02 \ imawasp03 \ imawasp04 \ imawasp05 \ imawasp06 \ imawasp07 \ imawasp08 \ imawasp09 do print "${SRV}" while read PASSLINE do SRVNAME=`echo ${PASSLINE} | awk -F\: '{print $1}'` LASTLOGIN=`ssh ${SRV} lsuser ${SRVNAME} | tr '... (2 Replies)
Discussion started by: port43
2 Replies

4. Shell Programming and Scripting

How to add trailer record at the end of the flat file in the unix ksh shell scripting?

Hi, How to add trailer record at the end of the flat file in the unix ksh shell scripting can you please let me know the procedure Regards Srikanth (3 Replies)
Discussion started by: srikanth_sagi
3 Replies

5. Shell Programming and Scripting

Need a ksh script for adding the space at the end of record in a flat file

Hi, I need a ksh script for the below requirement: i have a Delimited flat file with 200 records delimiter is '|~|' i need a script to insert space at the end if the record is ending with delimiter '|~|' if it didnt end with delimiter it should not append space. Example: ram|~|2|~| ... (16 Replies)
Discussion started by: srikanth_sagi
16 Replies

6. Shell Programming and Scripting

Help in writing a KSH script to filter the latest record?

Hi All, I have a text file with the folowing content. BANGALORE|1417|2010-02-04 08:41:04.174|dob|xxx BANGALORE|1416|2010-02-04 08:23:19.566|dob|yyy BANGALORE|1415|2010-02-04 08:20:14.497|dob|aaa BANGALORE|1414|2010-02-04 08:19:40.065|dob|vvv BANGALORE|1413|2010-02-04... (4 Replies)
Discussion started by: Karpak
4 Replies

7. Shell Programming and Scripting

How to break record

I have this script lines #!/usr/bin/bash my_path=`dirname $0` I_table=$1 echo $I_table in I_table entry going is ccc_con,cc_gui I want to break content of I_table in S_Table and T_table on basis of comma as separtor (2 Replies)
Discussion started by: scorp_rahul23
2 Replies

8. Shell Programming and Scripting

ksh scripting: Extract 1 most recent record for unique key

I'm loading multiple delimited files into an Oracle DB using sqlldr on Unix. I would like to get only the most recent record per each unique key. There may be multiple updates for each key, but I only want the most recent one. There is a date column in my delimited files, so I'm using cat to... (2 Replies)
Discussion started by: OPTIMUS_prime
2 Replies

9. Shell Programming and Scripting

ksh how user can break out of loop

Hi Folks, I am trying to write a simple script which involves a potentially infinite loop repeating a number of tasks quickly. I would like to enable the user to break out of this when he/she wishes (some key stroke) but not to break out of the script (i.e. which is what happens when a user... (4 Replies)
Discussion started by: beckett
4 Replies

10. Shell Programming and Scripting

ksh script: 'exit' being treated as 'break 2'

hi, in a korn shell script, has anyone ever seen an 'exit' being treated as a 'break 2'? I have a script which has 3 nested loops. Within the inner most loop, i'm trying to exit the script on a fault condition. instead of exiting, it's acting as a 'break 2' and then continuing on with the... (4 Replies)
Discussion started by: gsatch
4 Replies
Login or Register to Ask a Question