Help with number field manipulation


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with number field manipulation
# 1  
Old 05-03-2012
Help with number field manipulation

I have a comma separated file containing numbers, I would like to read the file and divide each number by 1024 and create an output file.

Input file :

Code:
50312.00,3434.05, ,3433.34,124344.00,434343.00, , ,

Output file:

Code:
49.13,3.35,3.35,0,12.05,424.16,0,0

Moderator's Comments:
Mod Comment Please click this link: How to use [code][/code] tags

Last edited by Scrutinizer; 05-03-2012 at 03:45 AM.. Reason: code tags
# 2  
Old 05-03-2012
Try this,
Code:
awk -F"," '{for(i=1;i<=NF;i++){print $i/1024;}}' txt  > txt1

Regards,
Indu

Last edited by Indumathy; 05-03-2012 at 04:08 AM..
# 3  
Old 05-03-2012
Code:
nawk -F, -v OFS=, '{for(i=1;i<=NF;i++){$i=$i/1024}}1' input.txt > output.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File manipulation place 0 before the number using sed

I'm new with sed, and i am really confused with slashes, backslashes, parentheses, I've tried reading some beginner's guide, but still trouble fixing this problem, do you have any tips where or what to read to learn more about sed? can you also help me with my problem? Note: I was tasked to use... (4 Replies)
Discussion started by: akopocpoypoy
4 Replies

2. Shell Programming and Scripting

Squence number manipulation in Shell

Hello Forum, I am receiving a file daily like ASAD but at the end there is a counter like 0012 (4 digits) so my every next file +1 I want to write a control script and check the last sequence number.Let's say If I receive a file ASAD0012 then after receiving this file I wan to say that... (5 Replies)
Discussion started by: cemokam65
5 Replies

3. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

4. Shell Programming and Scripting

Line number based manipulation

Hi I have a case where I am grabbing patterns and subsequent lines using sed -n -e '/regex/{$!N;p;}' This returns just the regex line when it is the last line of my file. Now I may have even number of lines in some cases (regex never at end) and odd in very rare cases. If the line... (6 Replies)
Discussion started by: jamie_123
6 Replies

5. UNIX for Dummies Questions & Answers

Finding numbers in lines with strings and number and doing some manipulation

Hi, I want to write a script that does something like this: I have a file, in which in every line, there is a string of words, and followed by some space, a number. Now, I want to identify the line, which has the largest startFace number (say m=8118), take that number and add it to the... (2 Replies)
Discussion started by: super_commando
2 Replies

6. Shell Programming and Scripting

Adding total of first field for each number in the second field

Dears, I need a script or command which can find the unique number from the second filed and against that number it adds the total of first field . 17215630 , 0 907043 ,1 201050 ,10 394149 ,4 1964 ,9 17215630, 0 907043 ,1 201050, 10 394149 ,4 1964 ,9 1234234, 55 23 ,100 33 ,67 ... (2 Replies)
Discussion started by: shary
2 Replies

7. Shell Programming and Scripting

date field manipulation

I have a data file. Seperated by "|". The 19 th filed is a date field that occurs like this 11/02/2001 i need to convert into the below format 2001-11-02 for e.g.. i/p o/p should be can somebody throw some light (5 Replies)
Discussion started by: dsravan
5 Replies

8. Shell Programming and Scripting

Count number of occurences of a character in a field defined by the character in another field

Hello, I have a text file with n lines in the following format (9 column fields): Example: contig00012 149606 G C 49 68 60 18 c$cccccacccccccccc^c I need to count the number of lower-case and upper-case occurences in column 9, respectively, of the... (3 Replies)
Discussion started by: s052866
3 Replies

9. Shell Programming and Scripting

Sorting on two fields time field and number field

Hi, I have a file that has data in it that says 00:01:48.233 1212 00:01:56.233 345 00:09:01.221 5678 00:12:23.321 93444 The file has more line than this but i just wanted to put in a snippet to ask how I would get the highest number with time stamp into another file. So from the above... (2 Replies)
Discussion started by: pat4519
2 Replies

10. Shell Programming and Scripting

Subtract 100 from first field in long list? Simple manipulation?

It sounds so easy to do. I have a file thats laid out like this.. number text text text text (etc about 15 times with various text fields) I want to take the first field, "number", subtract 100 from it, and then put it back in the file. a simple little manipulation of the first field in... (4 Replies)
Discussion started by: LordJezo
4 Replies
Login or Register to Ask a Question