Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    India
    Posts
    114

    Unanswered: Scramble solution

    I have a file in UNIX. Each record in the file is 852 characters.

    As per my requirement I have to replace the contents of file in each record from position 38 to 348 as “*”. These fields will have very sensitive data and we want to hide it with *.

    I tried sed using –r option but the –r option doesn’t work.

    Could you people please suggest something using AWK , SED or whatever. This is a urgent requirement.

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    Untested:
    Code:
    sed -e 's/\(.........38x....\).*/\1***********310x*****/g'
    Or you can cut the first 38 characters from each line and concatenate it with 310x *.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Nov 2003
    Location
    India
    Posts
    114
    cThanks for the reply. But I don't want to use 310 asterik * signs... Can some command or loop help me in this

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    This what you want to do?
    Lets assume you need to replace columns 15-20 with a single *
    Code:
    cat xx
    ABCDEFGHIJKLMNOPQRSTUVWXYZ
    ----+----1----+----2----+-
    
    cut -c 1-15,21- <xx | sed 's/./*/15'
    ABCDEFGHIJKLMN*UVWXYZ
    ----+----1----*----+-

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

    Talking Or maybe....

    Or maybe this?:
    Code:
    $ beg=15
    $ end=20
    $ echo "ABCDEFGHIJKLMNOPQRSTUVWXYZ"|\
    > awk -v r="$beg,$end" 'BEGIN {split(r,q,",");for (i=q[1];i<=q[2];++i) a=a"*";}
    > {o=substr($0,1,q[1]-1) a substr($0,q[2]+1); print o;}' 
    ABCDEFGHIJKLMN******UVWXYZ
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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