Question about working with data to create new column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question about working with data to create new column
# 1  
Old 08-21-2007
Question about working with data to create new column

Hello,

I am having a problem with the script I am using to create a column from two columns I have in my file. I am needing to take column 5 and subtract it from column 2 to create column 6. I have included the script I am using and the rawdata I am using.

Raw Data File:
20070701,000004627,encode,29898,13620

Script

####usage: ./date_comp.sh >>outputfilename
awk '{$6=$2-$5
len="%0"length($2)"d"
$6=sprintf(len,$6)
$1=$1
print
}' "file_name"


Thanks in Advance.
# 2  
Old 08-21-2007
nawk -f scott.awk myFile

scott.awk:
Code:
BEGIN {
  FS=OFS=","
}

  {
     format="%0" length($2) "d"
     $(NF+1)=sprintf(format, $2 - $5)
     print
  }

# 3  
Old 08-21-2007
vgersh99,

Thanks for the swift reply. I appreciate your assistance. I hate being very rusty and trying to relearn something. LOL Question would that work also for doing a multiple series of math? Meaning I have a column that I want to do math upon. I am taking the column and multiplying it by 0.125, then that total will be subtracted by 1, then that total will be multiplied by 0.0225 for the final total.

((Column*0.125)-1)*0.0225=new column

Meaning would I be able to do something like this:

BEGIN {
FS=OFS=","
}

{
format="%0" length($2) "d"
$(NF+1)=sprintf(format, ((($4*0.125)-1)*0.0225))
print
}
# 4  
Old 08-21-2007
yes, it would - with the slight 'possible' modification. As you're dealing with the floating numbers for your multiplications, you'd probably want to display the 'final total' using floating notation:
Code:
format="%0" length($2) "f"

try it out - see what happens.
# 5  
Old 08-21-2007
Thanks Again. That was the ticket. I appreciate the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to insert data into black column( Secound Column ) in excel (.XLSX) file using shell script?

Source Code of the original script is down below please run the script and try to solve this problem this is my data and I want it column wise 2019-03-20 13:00:00:000 2019-03-20 15:00:00:000 1 Operating System LAB 0 1 1 1 1 1 1 1 1 1 0 1 (5 Replies)
Discussion started by: Shubham1182
5 Replies

2. Shell Programming and Scripting

Change data in one column with data from another file's column

Hello, I have this file outputData: # cat /tmp/outputData __Capacity^6^NBSC01_Licences^L3_functionality_for_ESB_switch __Capacity^2100^NBSC01_Licences^Gb_over_IP __Capacity^1837^NBSC01_Licences^EDGE_BSS_Fnc __Capacity^1816^NBSC01_Licences^GPRS_CS3_and_CS4... (1 Reply)
Discussion started by: nypreH
1 Replies

3. Shell Programming and Scripting

Regexes for three column data to create a dictionary

I am working on a multilingual dictionary and I have data in three columns. The data structure can be word=word=gloss or word word=word word=gloss gloss = acts as a delimiter The number of words separated by the delimiter can be up to 8 or 10. The structure is well defined in the sense... (6 Replies)
Discussion started by: gimley
6 Replies

4. Shell Programming and Scripting

Split column data if the table has n number of column's with some record

Split column data if the table has n number of column's with some record then how to split n number of colmn's line by line with records Table --------- Col1 col2 col3 col4 ....................col20 1 2 3 4 .................... 20 a b c d .................... v ... (11 Replies)
Discussion started by: Priti2277
11 Replies

5. Shell Programming and Scripting

Compare 2 files of csv file and match column data and create a new csv file of them

Hi, I am newbie in shell script. I need your help to solve my problem. Firstly, I have 2 files of csv and i want to compare of the contents then the output will be written in a new csv file. File1: SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0713.JPG,2015:02:17 11:14:07... (8 Replies)
Discussion started by: refrain
8 Replies

6. Shell Programming and Scripting

Compare 2 files and match column data and align data from 3 column

Hello experts, Please help me in achieving this in an easier way possible. I have 2 csv files with following data: File1 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:35:47,JOB_5330 08/23/2012 12:36:09,JOB_5340 08/23/2012 12:36:14,JOB_5340 08/23/2012 12:36:22,JOB_5350 08/23/2012... (5 Replies)
Discussion started by: asnandhakumar
5 Replies

7. Shell Programming and Scripting

AWK script to create max value of 3rd column, grouping by first column

Hi, I need an awk script (or whatever shell-construct) that would take data like below and get the max value of 3 column, when grouping by the 1st column. clientname,day-of-month,max-users ----------------------------------- client1,20120610,5 client2,20120610,2 client3,20120610,7... (3 Replies)
Discussion started by: ckmehta
3 Replies

8. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

9. Shell Programming and Scripting

create a new file from data file from a column

I have a data file that has a list of data macthing by user. I am able to sort by user and there is multiple rows for each user. Ideally I would like to email only the user of the files they own. Would it be best to create a seperate file by user and all rows showing the files they own? (9 Replies)
Discussion started by: mykey242
9 Replies

10. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies
Login or Register to Ask a Question