Results 1 to 4 of 4

Thread: mv txt to csv

  1. #1
    Join Date
    Aug 2008
    Posts
    464

    Unanswered: mv txt to csv

    Hi

    Kind of new to unix scripting.

    I'm trying to write a script to rename the extension of some files from .txt to .csv in HPUX. There's a folder on the HPUX server where .txt files will constantly be downloading 24hrs every 30 min.

    I tried to write a shell script to rename the extension but it's not worked.

    Code:
    #!/bin/sh
    $1="*.txt"
    $2="*.csv"
    for i in *.txt;
    do
    mv $1 $2;
    done
    Also tried: But to no avail.
    Code:
    #!/bin/sh
    TXT="*.txt"
    CSV="*.csv"
    
    for i in TXT;
    do 
    echo $i;
    mv $TXT $CSV;
    done
    and
    Code:
    #!/bin/sh
    for i in folderpath/*.txt
    do
    echo $i 
    mv $i newfolderpath/*.csv
    done
    If anyone could point me in the right direction?
    Last edited by shajju; 02-17-14 at 10:52.

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Talking

    Try this:
    Code:
    #!/bin/ksh
    for i in /folderpath/*.txt
    do
      n=${i%%.*}
      mv $i /newfolderpath/${n}.csv
    done
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Aug 2008
    Posts
    464
    Thanks.

    The newfilepath is dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/${n}.csv.

    When I
    Code:
    echo "n=${i%%.*}"
    I get n=dir1/dir2/dir3/dir4/dir5/dir

    Note: There is no '6' so what I'm trying to say is that part of the name for dir6 is stripped off.

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Can you post the real source and destination directory names, and a sample of the text file names?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •