Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Posts
    92

    Unanswered: adding a column at the end of the record

    hello.,

    i have a .txt file.

    inside the .txt file i have.,

    /home/ss/cca.costco.transaction_date
    /home/sk/cca.costco.transaction_date
    /home/st/cca.costco.transaction_date
    /home/sv/cca.costco.transaction_date

    cca.costco.transaction_date is the file name.
    inside the file there are some 100 records.
    there are 28 columns. each field is comma
    delimited.

    i have to add a 29th column in each record
    in each file. once it adds a number
    in all the records in that file next it has
    to go to the next file and add the number in 29th
    columns in the next file.

    it has to do it for all the files in that .txt file.

    say i have to add a number
    123 in the 1st file, 135 in 2nd file so on


    this is my business requirement.

    can anyone help me in doing this

    thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Rome, Italy
    Posts
    81

    Smile

    try this:

    ---------------------------------
    for i in `cat a.txt`
    do
    echo "Insert the value you want to add as the last column to the file $i : "
    read col
    awk -v var=$col '{printf $0 FS var "\n"}' $i >$i.new
    done
    -----------------------------------


    bye,
    ducasio

Posting Permissions

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