minus col1 and col2


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers minus col1 and col2
# 1  
Old 01-01-2009
minus col1 and col2

my file looks like this:
101928 101943
101928 101944
101929 101943
101929 101943
101929 102044

i want to insert bc to get answer like this:

101928 101943 000015
101928 101944 000016
101929 101943 000013
101929 101943 000014
101929 102044 000115

total 000173

my way:
create two files (col2.txt and col2.txt)

cat col2.txt | while read col2
do
cat col1.txt | while read col1
do
echo $col2 - $col1 | bc > total.txt

done
done

must be a short version of it.
# 2  
Old 01-01-2009
i searched thru unix.com and i found this syntax:

awk -F" " 'BEGIN {x=0} {x+=$2} END {print x}' cols

i made it work the way i want it.

thanks anyway.....
# 3  
Old 01-01-2009
Try:

Code:
awk '{ printf("%s %06d\n", $0,$2-$1); }' filename

# 4  
Old 01-01-2009
dj,

thanks. worked perfectly.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get a time minus 60 minutes?

Hello, date --date '-60 min ago' +'%Y-%m-%d %H:%M:%S,%3N' Above command gives the date and time minus 60 minutes but the problem i am facing is, i do not want to hardcode the value 60 it is stored in a variable var=60 now if i run below command , i get error date --date '-$var min... (3 Replies)
Discussion started by: Ramneekgupta91
3 Replies

2. UNIX for Dummies Questions & Answers

Minus 5 minutes

Hi, I need to subtract 5 minutes from the date. Example $date +"%Y-%m-%d-%H.%M.%S" displays 2014-06-26-06.06.38 I want to show it as 2014-06-26-06.01.38 (5 mins are subtracted from date) Any help would be appreciated. I am currently on AIX version 6.1 -Vrushank (10 Replies)
Discussion started by: vrupatel
10 Replies

3. UNIX for Dummies Questions & Answers

If col1 and col2 of any line in both of two files in two files match, col1 and col2

I have two files, and I'm interested in the first two columns of each. File1 compares set1 to set2 (column1 = set1 name, column2 = set2 name). File2 compares set2 to set1 (column1 = set2 name, column2 =set1 name). I want to print the set names (column values) that appear as pairs in both... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

4. Shell Programming and Scripting

Merging data from col 3 to col2 with awk or sed

Dear Friends, I have a file in which lists State and Phone numbers. Does anybody have a solution in which to take the data from col3 and place it on col2? AK 2988421640 9077467107 AK 2998266711 2069239034 AK 2983804242 2069239034 AK 2960407849 AK ... (3 Replies)
Discussion started by: liketheshell
3 Replies

5. Shell Programming and Scripting

Minus minus to plus

Hi there, I have a problem with arithmetic ops in awk. Here is what my script does right now. while read nr val ; do case $nr in 400) awk '$2~/eigenvectors/ {print $NF-'$val'};' input.txt >> output.txt;; esac done < frames.txtI have a file named frames.txt with two columns (nr and... (2 Replies)
Discussion started by: tobias1234
2 Replies

6. Shell Programming and Scripting

Minus of files

File 1 contains data : CALL_ID SOR_ID SEG_SEQ_NUM CHK_PNT_MENU_TYPE_CD PTNR_ID ACTVN_RTRN_CD PRIM_ACTVN_DCLN_REAS_CD SCNDRY_ACTVN_DCLN_REAS_CD ACTVN_SCCS_IND CARD_ACTVTD_IND MAX_ACTVN_FAILD_ATMP_IND EDW_PUBLN_ID File 2 contains data: PRIM_ACTVN_DCLN_REAS_CD... (3 Replies)
Discussion started by: ysvsr1
3 Replies

7. Shell Programming and Scripting

Awk - Count instances of a number in col1 and put results in a col2 (new) of diff file

I have 2 files as follows: filename1: : 6742 /welcome/mundial98_ahf1_404.htm 1020 6743 /welcome/mundial98_ahf1_404.htm 2224 6744 /welcome/mundial_ef1_404.htm 21678 6745 /welcome/mundial_if_404.htm 4236 6746 /welcome/mundial_lf1_404.htm 21678 filename2: 6746 894694763 1... (2 Replies)
Discussion started by: jontjioe
2 Replies

8. Shell Programming and Scripting

Replace a column with a value conditional on a value in col1

Hi, Perhaps a rather simple problem...? I have data that looks like this. BPC0013 ANNUL_49610 0 0 1 1 BPC0014 ANNUL_49642 0 0 2 1 BPC0015 ANNUL_49580 0 0 1 1 BPC0016 ANNUL_49596 0 0 2 1 BPC0017 VULGO_49612 0 0 1 1 BPC0018 ANNUL_49628 0 0 1 1 BPC0019 ANNUL_49692 0 0 2 1 170291_HMG... (4 Replies)
Discussion started by: genehunter
4 Replies

9. Shell Programming and Scripting

Minus of 2 files -- Please help

Hello people, awk '{print $0}' input1.txt input2.txt |sort -u Will give the union of the 2 files. Similarly what is command to get just the diff data (i.e minus) of the 2 files. Can I use the "diff" command to get just the diff data. Please let me know. Regards, Tipsy. (7 Replies)
Discussion started by: tipsy
7 Replies

10. UNIX for Dummies Questions & Answers

minus sign

why a minus sign is put for options in unix commands suggestions plz (2 Replies)
Discussion started by: trichyselva
2 Replies
Login or Register to Ask a Question