Results 1 to 7 of 7

Thread: Unix script to update specific field in data files

  1. #1
    Junior Member
    Join Date
    Sep 2005
    Posts
    29
    Thanks
    3
    Thanked 2 Times in 1 Post
    Rep Power
    0

    Default Unix script to update specific field in data files

    My data is as follows
    Code:
    date info number dr cr close
    How do I update number field from
    Code:
    112
    113
    114
    to
    Code:
    00112
    00113
    00114
    I'm on Solaris UNIX and KSH shell.

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,498
    Thanks
    17
    Thanked 788 Times in 506 Posts
    Rep Power
    10

    Default

    How is your data separated by white space, tab or comma?
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    sukujgrg
    Guest

    Default

    If you have awk in your system it is very simple as opening a file with same..

    awk '{ print $1"\t"$2"\t"00$3"\t"$4"\t"$5"\t"$6 }' filename
    ----
    Suku

    Last edited by nixcraft; 9th September 2010 at 12:33 PM. Reason: Spam and self promotion not allowed. See TOS.

  4. #4
    Senior Member
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    0
    Thanked 33 Times in 29 Posts
    Rep Power
    11

    Default

    Quote Originally Posted by sukujgrg View Post
    If you have awk in your system it is very simple as opening a file with same..
    Code:
    awk '{ print $1"\t"$2"\t"00$3"\t"$4"\t"$5"\t"$6 }' filename
    Code:
    awk '{ $3="00"$3}1' OFS="\t" filename

  5. #5
    sukujgrg
    Guest

    Default

    Quote Originally Posted by ghostdog74 View Post
    Code:
    awk '{ $3="00"$3}1' OFS="\t" filename
    Can you please explain the meaning of "1" ('{ $3="00"$3}1') in you one liner.

  6. #6
    Senior Member
    Join Date
    Sep 2006
    Posts
    131
    Thanks
    0
    Thanked 33 Times in 29 Posts
    Rep Power
    11

    Default

    that's the shorthand for "print" in awk

  7. #7
    sukujgrg
    Guest

    Default

    Thanks for the information.

    ----
    Suku

    Last edited by nixcraft; 9th September 2010 at 12:33 PM. Reason: Spam and self promotion not allowed. See TOS.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Solved] UNIX KSH Script Separate Lines By Field
    By yogeshverma in forum Shell scripting
    Replies: 6
    Last Post: 2nd September 2009, 04:45 PM
  2. Replies: 0
    Last Post: 6th January 2009, 03:02 PM
  3. Script for accessing data ..
    By Dastard in forum Shell scripting
    Replies: 1
    Last Post: 25th July 2006, 11:12 PM
  4. Script to extract a specific row of data
    By ricc in forum Shell scripting
    Replies: 1
    Last Post: 15th November 2005, 02:29 PM
  5. script to rewrite data.
    By kavi in forum Shell scripting
    Replies: 3
    Last Post: 18th September 2005, 12:13 AM

Posting Permissions

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