LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 07-11-2014, 01:07 AM   #1
hoi
Member
 
Registered: Jun 2013
Posts: 32

Rep: Reputation: Disabled
decoration of data file


I have a file like:
1 17 0.866
1 18 0.866
1 19 0.866
1 21 0.866
2 17 0.866
2 18 0.866
2 20 0.866
2 22 0.866
3 17 0.866
3 19 0.866
3 23 0.866
3 26 0.866
1 10 1.000
1 11 1.000
2 11 1.000
2 12 1.000
3 15 1.000
3 16 1.000


I want to modify the above file with respect to column three, into two files.
file1:
1 17 18 19 21
2 17 18 20 22
3 20 19 23 26

file2:
1 10 11
2 11 12
3 15 16
 
Old 07-11-2014, 08:45 AM   #2
kaushalpatel1982
Member
 
Registered: Aug 2007
Location: INDIA
Distribution: CentOS, RHEL, Fedora, Debian, Ubuntu, LinuxMint, Kali Linux, Raspbian
Posts: 166

Rep: Reputation: 10
There is problem in FILE1 line 3, Output should be :

"3 17 19 23 26" instead of "3 20 19 23 26"


Code:
#!/bin/bash
j=3

i=1
while [ $i -le $j ]
do
	values=`cat file | grep 0.866 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
	echo $i $values >> file1
	i=`expr $i + 1`
done

i=1
while [ $i -le $j ]
do      
        values=`cat file | grep 1.000 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
        echo $i $values >> file2
	i=`expr $i + 1`
done

Last edited by kaushalpatel1982; 07-11-2014 at 08:48 AM.
 
2 members found this post helpful.
Old 07-12-2014, 01:08 AM   #3
hoi
Member
 
Registered: Jun 2013
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kaushalpatel1982 View Post
There is problem in FILE1 line 3, Output should be :

"3 17 19 23 26" instead of "3 20 19 23 26"


Code:
#!/bin/bash
j=3

i=1
while [ $i -le $j ]
do
	values=`cat file | grep 0.866 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
	echo $i $values >> file1
	i=`expr $i + 1`
done

i=1
while [ $i -le $j ]
do      
        values=`cat file | grep 1.000 | awk '{ print $1, $2 }'| grep ^$i | cut -d" " -f2 | xargs -n 5`
        echo $i $values >> file2
	i=`expr $i + 1`
done
Thank you Kaushal....
 
  


Reply

Tags
bash scripting, c programming, cprogramming, shell script



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
I am getting binary data in file.but i want normal data .PLEASE HELP batman4 Programming 7 07-24-2012 07:53 AM
Over my head with this problem - Access the data in .fbd data file BobNutfield Linux - Server 3 02-20-2011 01:48 PM
Replace data of one column with data on other file corresponding to transaction ID saurabhmehan Linux - Newbie 1 12-23-2010 01:19 AM
gnuplot, pull X data from file, specify Y data at cmd line? hedpe Programming 5 03-15-2007 11:32 PM
Console without decoration theonebeyond Linux - General 2 10-29-2004 04:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:28 AM.

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
Open Source Consulting | Domain Registration