Manipulating Columns!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Manipulating Columns!
# 1  
Old 04-11-2012
Manipulating Columns!

Hello Experts,
I have .txt file which has various columns and 4 rows.
Code:
cat input.txt
Cont x y z k
Max 0.3 0.9 0.4 0.6
Min  0.2 0.9 0.3 0.6
Diff 0.1 0 0.1 0
 
Output:
Cont x y z k
Max 0.5 1.1 0.6 0.8
Min  0.1 0.7 0.2 0.4
Diff 0.4 0.4 0.4 0.4

That means if the diff between the Max and Min is 0.1 than add 0.2 to max value and subtract 0.1 to min value, if diff is 0 than add 0.2 to max and subtract 0.2 to min value. I had to code this in csh script since this script will be part of bigger script written in csh.
Thanks in advance.
# 2  
Old 04-11-2012
Quote:
Originally Posted by dixits
Hello Experts,
I have .txt file which has various columns and 4 rows.
Code:
cat input.txt
Cont x y z k
Max 0.3 0.9 0.4 0.6
Min  0.2 0.9 0.3 0.6
Diff 0.1 0 0.1 0
 
Output:
Cont x y z k
Max 0.5 1.1 0.6 0.8
Min  0.1 0.7 0.2 0.4
Diff 0.4 0.4 0.4 0.4

That means if the diff between the Max and Min is 0.1 than add 0.2 to max value and subtract 0.1 to min value, if diff is 0 than add 0.2 to max and subtract 0.2 to min value. I had to code this in csh script since this script will be part of bigger script written in csh.

Use awk; that way you can incorporate it into any script, even one written in csh
Code:
awk '
NR == 1 { print }
NR == 2 { cols1 = split($0,max) }
NR == 3 { cols2 = split($0,min) }
NR == 4 { cols3 = split($0,diff) }

END {
 ### do the calculations on the elements of the arrays
 ### and print the results (gotta run, sorry)
}

' input.txt


Top Ten Reasons not to use the C shell
Csh problems
Csh Programming Considered Harmful
# 3  
Old 04-12-2012
Seeing your other thread, have you had any luck with this, dixits? If not, what have you tried? You've got a good template to work from there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Manipulating files

Not sure if the question posted in another forums can be moved by me.So posting the link here. https://www.unix.com/unix-advanced-expert-users/221425-shell-script-manipulate-files.html#post302795379 Need your help here. (1 Reply)
Discussion started by: vedanta
1 Replies

2. Shell Programming and Scripting

Manipulating Filenames

Hi Folks, I'm looking for some ideas on how to change some file names. I'm pretty sure I need to use sed or awk but they still escape me. The files I have are like: VOD0615 NEW Blades R77307.pdf or VOD0615_NEW_Blades_R77307.pdf and what I want after processing is: R77307 NEW Blades.pdf ... (5 Replies)
Discussion started by: imonkey
5 Replies

3. UNIX for Dummies Questions & Answers

Manipulating files

Hi Guys, I'm really new to Unix and Linux and other scripting languages but recently I hv been really enthusiatic about learning more to help out on my work. So I have a file with 3 columns. A sample of it looks like looks like this : K2_537841 AAATCAGCCGCAACATTTGC ... (7 Replies)
Discussion started by: pawannoel
7 Replies

4. Shell Programming and Scripting

Manipulating a file

Hi everybody, I need an urgent help with a BASH script. I have file which contains (besides the other data) the lines with the following structure identified by with keyword PCList: <PARAMETER NAME="PCList" TYPE="LIST_STRUCTURE" MODEL="{,}" ... (1 Reply)
Discussion started by: sameucho
1 Replies

5. Shell Programming and Scripting

manipulating data

Hi guys Firstly, I'd like to say hi and how great this forum is. I'm not new to UNIX but am relatively new to scripting. I have a personal project that I'm working on just to try and speed up my learning. I working with a text file, well more of a logfile really. It has several columns of... (6 Replies)
Discussion started by: abcd69
6 Replies

6. Emergency UNIX and Linux Support

Manipulating Data

Hi. I haven't had to write bash scripts in a long time and have a simple task to do, but need some help: Input: chrY:22627291-22651542 chrY:23045932-23070172 chrY:23684890-23696359 chrY:25318610-25330083 chrY:25451096-25462570 chr10:1054847-1061799 chr10:1058606-1080131... (7 Replies)
Discussion started by: awknerd
7 Replies

7. UNIX for Dummies Questions & Answers

Help!! manipulating file

Hi all, I need help manipulating the file below. Here is what I needed to do. First, I have to replace INSUPD to DELETE. Then I need to change the content of the file around by flipping the contents in the file from the bottom to the top (start from "CMD") How should I attack this? Here... (2 Replies)
Discussion started by: sirrtuan
2 Replies

8. UNIX for Dummies Questions & Answers

string manipulating

I have a file like this: Tue Apr 15 10:41:47 MDT 2008 FINAL RESULT; 6 Tue Apr 15 10:41:47 MDT 2008 FINAL RESULT; 2 Tue Apr 15 10:41:47 MDT 2008 FINAL RESULT; 5 With this command seira=`cut -f 2 -d ';' tes.txt` i take all the results (6,2,5 etc) and i store them in variable seira When i do... (9 Replies)
Discussion started by: psalas
9 Replies

9. UNIX for Advanced & Expert Users

Manipulating two files

Hi Friends, I prefer to represent my problem with example. I have two files as below: file1.txt --------- abcd.....1234......XY abcd.....1235......XX abcd................. abcd...231236..1111YX abcd...241236..1112YY abcd...241237......YY abce.....1235......YY file2.txt ------- ... (4 Replies)
Discussion started by: rinku11
4 Replies

10. UNIX for Dummies Questions & Answers

date manipulating

I'm using Kshell scripts cronjobs to logrolling my daily log files and I stamped the log file at the end of the day by date stamp i.e.: %d_%m_%y-LogFile. but the 22_01_2001-LogFile as example contains 21st Jan data and I want to stamp the log file with previous day. so I'm trying to subtract... (3 Replies)
Discussion started by: tamer
3 Replies
Login or Register to Ask a Question