LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2012, 05:05 PM   #1
nricardo
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Rep: Reputation: Disabled
how to subtract selective values in multi row multi column (awk or sed ?)


Hi,

I have a problem where I need to make this input:

nameRow1a,text1a,text2a,floatValue1a,FloatValue2a,...,floatValue140a
nameRow1b,text1b,text2b,floatValue1b,FloatValue2b,...,floatValue140b

look like this output:

nameRow1a,text1b,text2a,(floatValue1a - floatValue1b),(floatValue2a - floatValue2b),...,(floatValue140a - floatValue140b)

I thought I could do this in awk, but I can't figure out how to read the 2 lines independently and assign them into arrays, to later be manipulated.

Any help is greatly appreciated, and thanks a lot in advance!
 
Old 10-13-2012, 12:11 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
I think you will need to explain further?

1. Are we assigning to arrays in awk or bash?

2. How does your example work with being stored in an array?

3. Please show your efforts to solve
 
Old 10-20-2012, 10:55 AM   #3
nricardo
LQ Newbie
 
Registered: Oct 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Sorry, I hadn't replied, but I found this piece of code would do the trick. Thanks

BEGIN {OFS = ",";}
{
nLine1 = split($0, Line1, ",");
getline;
nLine2 = split($0, Line2, ",");
getline;
for (i=1;i<=20;i++) $i = sprintf("%s", (Line1[i]) );
for (i=21;i<=141;i++) $i = sprintf("%.18f", (Line1[i] - Line2[i]) );
print;
}
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] grep/sed/awk multi line array earthgecko Programming 13 10-08-2012 02:06 PM
[SOLVED] Change row using awk based on column value akeka Programming 3 10-03-2012 03:43 AM
Get data from multi lined text file using awk, sed or perl - grep & cut not upto par cam34 Programming 4 07-02-2010 04:10 AM
[ask awk] remove certain row in a column dhodho Programming 18 06-08-2010 10:36 AM
how to grep awk or sed the first row and column Bone11409 Linux - Newbie 2 03-21-2010 09:18 PM


All times are GMT -5. The time now is 10:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration