perl script to korn shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl script to korn shell script
# 1  
Old 06-26-2012
perl script to korn shell script

I have a perl script which replaces "*" with "|" and "~" with "\n" also it takes the file content starting with ST till record starting with SE written a differnet file, I wanted this to be convereted into KSH script, can anyone help me

perl script:

Code:
perl -e '
$file_counter=0;
$in_record=0;
while(<>){
  s/\*/|/g;
  s/~/\n/g;
  if(/^ST/){
    $in_record=1;
    open (FILE, ">" , "file_$file_counter");
  }
  print FILE $_ if $in_record;
  if (/^SE/){
    close FILE; 
    $in_record=0;
    $file_counter++;
  }
}' <file location>

Moderator's Comments:
Mod Comment Please view this link: How to use [code]...[/code] tags

Last edited by Scrutinizer; 06-26-2012 at 04:33 AM.. Reason: code tags
# 2  
Old 06-26-2012
Did you try my awk suggestion? Did that not work?
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 06-26-2012
Hi, I tried and it worked fine, but here they were telling that not to use awk.

Let me suggest them with this again. But in the awk

Code:
awk -F\* '$1=="ST",$1=="SE"{if($1=="ST"){close(f);f="file" ++i} gsub(/~/,RS); $1=$1; print>f}' OFS=\| $HOME/Bharath/sampleX12

How can I modify the name of the file generated to be along with time stamp, also here I have exclusively hardcoded the file name along with path, how to write a looping that iterates and take the files matching a file name convention and process it 1 by 1 with the above awk? Can you please advice on that.

Last edited by Scrutinizer; 06-26-2012 at 05:14 AM.. Reason: code tags
# 4  
Old 06-26-2012
Who is telling you? Is this homework?

You can assign the current date to a parameter on the command line and use that parameter as part of the filename f. You can specify multiple input files on the command line, so unless you have really many files you do not need a loop..

Last edited by Scrutinizer; 06-26-2012 at 06:47 AM..
# 5  
Old 06-26-2012
Yes there will be n number of files to be processed. so how to do the looping part so that it take the file 1 by 1 till the last file.

Let me try for the file name with the date time stamp.
# 6  
Old 06-26-2012
Quote:
Originally Posted by Scrutinizer
Is this homework?
Why don't you answer this question?
# 7  
Old 06-26-2012
For adding time stamp in the file name getting generated, I modified the above awk as highlighted below

DATE=`date +%m%d%y%H%M%S`
file="214_"
awk -F\* '$1=="ST",$1=="SE"{if($1=="ST"){close(f);f=$file_$DATE ++i} gsub(/~/,RS); $1=$1; print>f}' OFS=\| infile

But its throwing me error with "$" sign.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pass script with parameter in korn shell script

I have written a script which will take input parameter as another script. However, if the script passed as input parameter has parameters then this script doesn't work. I have a script b.ksh which has 1 and 2 as parameters I have a script c.ksh which has 3,4 and 5 as parameters vi a.ksh... (1 Reply)
Discussion started by: Vee
1 Replies

2. UNIX for Advanced & Expert Users

Calling PERL from a Korn shell script

I am currently in Afghanistan and do not have access to some of the resources I normally do back in the US. Just accessed this site and it looks promising! Hopefully you will not find my question too much of a waste of your time. I write mostly Korn Shell and PERL on Solaris systems for the... (2 Replies)
Discussion started by: mseanowen
2 Replies

3. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

4. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

6. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

7. Shell Programming and Scripting

Korn Shell and Perl Administrative Script

I have this script that I want to be able to scan a list of IP address from a file (namlist and snifflist)and Hostnames of network devices to see if they are alive or down and if telnet port 23 is open. I originally started to write this in Korn Shell and ran into some issue trying to closed a... (0 Replies)
Discussion started by: metallica1973
0 Replies

8. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

9. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

10. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question