Issue regarding dos2unix perl script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue regarding dos2unix perl script
# 1  
Old 06-30-2011
Issue regarding dos2unix perl script

Hi All,

I have pearl script which will check and convert the file:
Code:
INFO("dos2unix_cmds".$#{$dos2unix_cmds});  
  if ( $#{$dos2unix_cmds} == 0 ) {
    my $convert_cmd =  $$dos2unix_cmds[0][0];
    my $rename_cmd  =  $$dos2unix_cmds[0][1];
    --conversion going here
else 
     INFO ("No need to convert... skipping this step.")

Now, here the value of $dos2unix_cmds is
Code:
dos2unix -437 -q <some_file_nm>

However it is going to else section, and my file still has ^M char!

Please help.
Please let me know if more info required.

Thanks, Saptarshi

---------- Post updated at 11:06 AM ---------- Previous update was at 06:09 AM ----------

One more thing, what does "$#" and "$$" mean in perl?

Last edited by pludi; 06-30-2011 at 08:28 AM..
# 2  
Old 06-30-2011
Quote:
Originally Posted by saps19
One more thing, what does "$#" and "$$" mean in perl?
$$ is the PID of the running program, I think. It could also be a double array reference though that seems dodgy. $# means the length of the array.

Could you post your entire script? Or for that matter, what your actual goal is? There's probably a simpler way to do it than a perl script.

I never liked dos2unix. Almost nobody has it, and when they do it's liable to screw up.
# 3  
Old 06-30-2011
Hi Corona688,

Please find the below script:
Code:
# Convert file to Dos2UNIX
$sql  = "SELECT compare_1_command, compare_2_command ";
$sql .= "FROM vw_app_file_validation ";
$sql .= "WHERE source_file_id =  $g_source_file_id AND validation_type = 'DOS2UNIX'";
INFO ("Executing SQL =>". $sql);
my $dos2unix_cmds = app_get_data($sql);
INFO("dos2unix_cmds".$#{$dos2unix_cmds});
if ( $#{$dos2unix_cmds} == 0 ) {
   my $convert_cmd = $$dos2unix_cmds[0][0];
   my $rename_cmd  = $$dos2unix_cmds[0][1];
  #Change to tmp Directory
   INFO ("Switch to tmp Directory => $g_tmp_dir");
   chdir($g_tmp_dir);
   INFO ("Converting Dos File to UNIX => $convert_cmd");
   system($convert_cmd);
   INFO ("Renaming File => $rename_cmd");
   system($rename_cmd);
}
else {
   INFO ("No need to convert... Skipping this step");
}

Logfile shows:
Code:
validation_type = 'DOS2UNIX'] [app_validate_file.pl[139]]
[2011/06/29 07:11:41] [INFO] [EXECUTING: SELECT compare_1_command, compare_2_command FROM vw_app_file_validation WHERE source_file_id =  21 AND validation_type = 'DOS2UNIX'] [APP_ORA.pm[222]]
[2011/06/29 07:11:41] [INFO] [Execute succeeded] [APP_ORA.pm[245]]
[2011/06/29 07:11:41] [INFO] [dos2unix_cmds-1] [app_validate_file.pl[143]]
[2011/06/29 07:11:41] [INFO] [No need to convert... Skipping this step] [app_validate_file.pl[162]]

The SQL SELECT query returns:
Code:
dos2unix -437 -q <some_file_nm>

However, the script is going to 'else' section as the logfile shows.
I still have ^M char in file.

Last edited by saps19; 06-30-2011 at 01:31 PM.. Reason: Need to change
# 4  
Old 06-30-2011
I think your $dos2unix_cmds needs to be a list, like @var, for $#var to return any sensible value. It will be 0 when var has 1 element, 1 when var has 2, etc.


If app_get_data doesn't return a list, you may need to turn it into one with

@dos2unix_cmds=split(/[ ]/, app_get_data($sql));
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 06-30-2011
can i use
Code:
if /usr/xpg4/bin/grep -qE [[:cntrl:]]

in perl?
# 6  
Old 06-30-2011
You can, if you wrap it in a system() call. like system("grep ...");

And its return value isn't boolean. It will return zero on success and some nonzero number on failure. So check for zero.
# 7  
Old 06-30-2011
I am just trying to learn perl script.. what i posted was already in PRD... could you please give me the area (with code) where i need to modify?

Warm Regards,
Saptarshi.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script exits when using UNIX2dos / dos2UNIX

I'm not sure why but my script quits automatically at the point where unix2dos / dos2unix command is used. :confused::confused::confused: How do a fix it? LOG_FILE=MADDY.txt unix2dos ${LOG_FILE} exec 2> $LOG_FILE 1>&2 echo ${LOG_FILE} The script exists after the below... (3 Replies)
Discussion started by: machomaddy
3 Replies

2. Red Hat

Oracle Linux issue - all files FTPed to it from windows need to to be processed with dos2UNIX

Hello Friends, I have observed one recent issue about ftp from windows to Linux. Initially we had Solaris unix and any file sent from windows to solaris via ftp (binary or ascii) worked smoothly. Say for e.g if I sent a shell script to soalris from windows, that script used to run corectly.... (17 Replies)
Discussion started by: Albert_Pinto7
17 Replies

3. Shell Programming and Scripting

Perl script issue

Hi All, I have a perl script which I am using in Windows environment. There is one more file called "functions.txt" which is having all the functions defined to used in my perl script. And the path for this function file is defined in my perl script. Howeever sometimes I am getting below error... (4 Replies)
Discussion started by: gr8_usk
4 Replies

4. Web Development

Accessing a Perl CGI script, security issue

Hi Everybody, I was wondering if it was possible for someone to gain access to my Perl CGI scripts before they are interpreted by Perl (mod_perl on apache2) i.e. getting a hold of my raw scripts and not the html output? Let's say I use the DBI module where I have the hostname, user and... (2 Replies)
Discussion started by: z1dane
2 Replies

5. Shell Programming and Scripting

Perl script issue: print

Can someone tell me what I'm doing wrong with my perl script? I am new to Perl. This isn't even the final script, I'm just testing to see if it will print the directories with the files in it. For some reason my output is only printing the 1st, 6th, and last entries of the @sub_dir array. Each... (3 Replies)
Discussion started by: man
3 Replies

6. Shell Programming and Scripting

Perl Script issue. What am I doing wrong?

#!/usr/local/bin/perl open (MYFILE, 'logs_report'); while (<MYFILE>) { $rec=$_; chomp ($rec); @arr=split(/ /,$rec); print $rec,"\n" if ($arr!~/OK/); open (MYF, '>data.txt'); print $rec,"\n" if ($arr!~/OK/); close (MYF); (14 Replies)
Discussion started by: SkySmart
14 Replies

7. Shell Programming and Scripting

dos2unix

hi, need some urgent inputs..... I have a folder, which has both files and directories as its contents. I want to convert all the files (Excluding the directories) from dos to unix mode using the command 'dos2unix'..... please can any one help me in providing the command to convert... (3 Replies)
Discussion started by: cmaroju
3 Replies

8. Shell Programming and Scripting

Perl Script Issue - Please Help * Thanks!!!

Please help me with my script please. I am trying to do the following: 1. Read files for the current directory 2. Open and read from nbe files files only 3. Read only the lines with the results pattern 4. Split the line and print 3rd field Please indicate what line I need to modify. ... (8 Replies)
Discussion started by: jroberson
8 Replies

9. UNIX for Dummies Questions & Answers

dos2unix - editing script - Help Urgent Please

Hi this is my first time on this forum so sorry if I posted this to the wrong area. I need help with the following. I have a basic FormMail cgi script I use. When I upload the script using filezilla, there is one line in the script that changes. The line should read &get_date; instead it... (2 Replies)
Discussion started by: lydp101
2 Replies

10. Shell Programming and Scripting

calling dos2unix on shell script from within the script

I have a build script. It was created on Linux. For some reason, I got it to windows and modified it. And brought it back again to Linux. Since there is the question of the ^M chars appearing, the way out is to do a dos2unix on the script file. This is done manually. Is there a way to call... (4 Replies)
Discussion started by: vino
4 Replies
Login or Register to Ask a Question