LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-04-2013, 10:17 AM   #1
enrollTN
LQ Newbie
 
Registered: Jun 2013
Posts: 3

Rep: Reputation: Disabled
Question perl scripts to change to uppercase and remove quotation marks.


Founds lots of examples in my search... however all it's doing is printing to the screen and not saving the file.

This is being ran with strawberry perl on windows 2008 server. The reason I'm here asking is 1. Most win admins would say use powershell, however i'm having a harder time getting it to work than perl.

here's what i have. Our filemaker database (don't laugh we're in the process of replacing it) generates a CSV file. However filemaker can't export in all caps. So I need to change this file, then ftp to another company.

1. Change all Text to Uppercase. I read and got the following to work:
Code:
perl -pe "$_= uc($_)" File1.csv > allcapsfile.txt
2. Remove the "'s from the file completely.
Code:
perl -pe s/\"//g allcapsfile.txt
This code just prints it to screen and not to a file. That's where I'm struggling.

I can remove the quotes using powershell but can't fix the caps. I guess I could write a .cmd that utilizes perl for one and powershell for the other... but I'd rather stick with one language.

If anyone has any advice I'd love to hear it. If this is the wrong place on the forums I apologize and will move it asap.
 
Old 06-04-2013, 12:46 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by enrollTN View Post
Founds lots of examples in my search... however all it's doing is printing to the screen and not saving the file.
This is being ran with strawberry perl on windows 2008 server. The reason I'm here asking is 1. Most win admins would say use powershell, however i'm having a harder time getting it to work than perl.

here's what i have. Our filemaker database (don't laugh we're in the process of replacing it) generates a CSV file. However filemaker can't export in all caps. So I need to change this file, then ftp to another company.

1. Change all Text to Uppercase. I read and got the following to work:
Code:
perl -pe "$_= uc($_)" File1.csv > allcapsfile.txt
2. Remove the "'s from the file completely.
Code:
perl -pe s/\"//g allcapsfile.txt
This code just prints it to screen and not to a file. That's where I'm struggling.

I can remove the quotes using powershell but can't fix the caps. I guess I could write a .cmd that utilizes perl for one and powershell for the other... but I'd rather stick with one language. If anyone has any advice I'd love to hear it. If this is the wrong place on the forums I apologize and will move it asap.
I realize you've posted perl, and may have a requirement/desire to use it, but there are sometimes easier solutions. You can accomplish both with a single Linux command line, and not use ANY programming language. This:
Code:
tr '[:lower:]' '[:upper:]' < File1.csv | sed 's/\"//g' > allcapsfile.txt
...turns everything into upper-case, and removes any double-quotes, and puts everything into a single output file, using only the tr and sed utilities, and Linux pipes/redirects. If this is something you do on a regular basis, you can even put that line into a shell-script, and have it 'watch' a specific directory, so any files that go IN, will be operated on automatically. A simple example, using inotifywait and a small do loop:
Code:
#!/bin/bash
inotifywait -m /some/path 2>&- | awk '$2 == "CREATE" { print $3; fflush() }' |
    while read file; do
        echo "$file is being processed"
        # Do your file operation here....
        tr '[:lower:]' '[:upper:]' < $file.csv | sed 's/\"//g' > /path/for/output/$file.txt
        # ....and move the file after processing to a different location here....
        mv /some/path/$file.csv /some/backup/path/
    done
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Replacing Quotation Marks With Nothing arnold.pietersen Programming 6 07-22-2012 05:37 AM
[SOLVED] how to use quotation marks in c++ stream knobby67 Programming 3 07-28-2011 02:07 AM
can not input double quotation marks(invalid quotation key) wangzhilife Linux - Hardware 2 09-18-2009 06:44 AM
nested `` quotation marks deathalele Programming 2 03-16-2009 01:31 PM
no quotation marks jdoe9898 Linux - Newbie 1 10-12-2005 03:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration