Results 1 to 10 of 10

Thread: sed in hpux

  1. #1
    Join Date
    Aug 2008
    Posts
    464

    Unanswered: sed in hpux

    Hi

    I have a folder on a HPUX Itanium B11.31 server containing a CSV file.

    I want to change all semi-colons to underscores in the file so I tried:

    Code:
    sed 's/:/_/g' filename
    Doing this it shows the output of the command correctly, but when I check the file, the file hasn't been changed.

    I've tried
    Code:
    sed -i
    but I get:

    Code:
    -bash-4.2$ sed -i 's/:/_/g' 0304172042316.csv
    sed: illegal option -- i
    Usage: sed [-n] [-e script] [-f source_file] [file...]
    Any ideas?

    Regards
    Sheraz Ahmad

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    According to the man page, the HP-UX version of sed doesn't support the GNU -i extension.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Aug 2008
    Posts
    464
    Thanks. So how can 'sed' be used with HPUX to replace file contents?

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I haven't used HP-UX sed, so treat these as general observations. Drop the -i parameter. You might need to explicitly specify an input file and an output file.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  5. #5
    Join Date
    Aug 2008
    Posts
    464
    Thanks, it's just that I needed to do this on 1000 files!

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    While there is no guarantee this will work, I've never had a problem using syntax like:
    Code:
    sed -i 's/:/_/g' >0304172042316.csv >0304172042316.csv
    to accomplish this kind of task. Since the sed commands won't change the size of the line and the output buffer is guaranteed to be as large or larger than the input buffer you should never encounter over-write conditions.

    To be completely safe, you should:
    1. rename the input file
    2. pipe the temp copy into sed
    3. Send the sed output back to the original file name
    This is a lot more work, and the shortcut that I mentioned above has never yet failed me.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  7. #7
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Do something along these lines.

    Code:
    mkdir out
    for I in *.csv 
    do
    sed 's/:/_/' < $I >out/$I
    done
    cd out
    mv * ..

  8. #8
    Join Date
    Aug 2008
    Posts
    464
    Code:
    sed -i
    is not an option in HPUX.

    I tried

    Code:
    sed 's/:/_/g' >0304172042316.csv >0304172042316.csv
    but that just deleted everything from the file (reduces it to 0 bytes).

    Please give an example for?

    rename the input file
    pipe the temp copy into sed
    Send the sed output back to the original file name

  9. #9
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    What do you think the script in post 7 does?

  10. #10
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Argh! I had a typo in my original code! It should have been:
    Code:
    sed -i 's/:/_/g' <0304172042316.csv >0304172042316.csv
    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

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