Request a script on manupilating the data. Please HELP!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Request a script on manupilating the data. Please HELP!
# 1  
Old 11-06-2010
Request a script on manupilating the data. Please HELP!

Dear friends,

I'm struggling to preparing a bunch of gaussian input files, say manually. It's really a time-consuming work without any techniques. I suppose that it could be done by a smart script automatically. But I lack some basic knowledge on scripting. Please help!

My original input looks like,
Code:
 C              
 H                  1    1.07000000
 H                  1    1.07000000    2  109.47120259
 H                  1    1.07000000    2  109.47120261    3  120.00001480    0
 H                  1    1.07000000    2  109.47123158    4  119.99999268    0

the modified output should be in the following format,
Code:
 C              
 H                  1    B1
 H                  1    B2    2  A1
 H                  1    B3    2  A2    3  D1    0
 H                  1    B4    2  A3    4  D2    0
B1 1.0700000
B2 1.0700000
B3 1.0700000
B4 1.0700000
A1 109.47120259
A2 109.47120259
A3 109.47120259
D1 120.00001480
D2 119.99999268

Clearly to say, the script would do:
1. we would get the total line number N by "wc -l"
1. replace the numbers in third column by B1~B(N-1), respectively, and add B1~B(N-1) to the end of the file followed by the replaced number.
2. replace the numbers in the 5th column by A1~A(N-2), respectively, and add A1-A(N-2) to the end of the file followed by the replaced number.
3. replace the numbers in the 7th column by D1~D(N-3), respectively, and add D1-D(N-3) to the end of the file followed by the replaced number.

I hope I have already made a clear statement about this script. Please do me a favor. All you help will be greatly appreciated. Thank you in advanced!

ZHEN
from Shanghai, China.

Last edited by liuzhencc; 11-06-2010 at 10:55 PM..
# 2  
Old 11-07-2010
Code:
OUT=outfile

awk '{for (i=3;i<=NF;i=i+2) 
       { if (i==3) $i="B"++j
         if (i==5) $i="A"++k
         if (i==7) $i="D"++l
       }
     }1' infile > $OUT

awk 'NF>1 {print "B" ++i,$3}' infile >> $OUT
awk 'NF>3 {print "A" ++i,$5}' infile >> $OUT
awk 'NF>5 {print "D" ++i,$7}' infile >> $OUT


Code:
$ cat outfile

 C
H 1 B1
H 1 B2 2 A1
H 1 B3 2 A2 3 D1 0
H 1 B4 2 A3 4 D2 0
B1 1.07000000
B2 1.07000000
B3 1.07000000
B4 1.07000000
A1 109.47120259
A2 109.47120261
A3 109.47123158
D1 120.00001480
D2 119.99999268

# 3  
Old 11-07-2010
Code:
awk ' NF>2{f=$3;$3="B"++b; B=B (B?RS:x) $3 FS f}
      NF>4{f=$5;$5="A"++a; A=A (A?RS:x) $5 FS f}
      NF>6{f=$7;$7="D"++d; D=D (D?RS:x) $7 FS f}
      $1=$1
      END {print B; print A; print D}' infile

Code:
C
H 1 B1
H 1 B2 2 A1
H 1 B3 2 A2 3 D1 0
H 1 B4 2 A3 4 D2 0
B1 1.07000000
B2 1.07000000
B3 1.07000000
B4 1.07000000
A1 109.47120259
A2 109.47120261
A3 109.47123158
D1 120.00001480
D2 119.99999268

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 11-07-2010
thanks you very much . both scripts work well for my case. Many thanks!
# 5  
Old 11-07-2010
Quote:
Originally Posted by Scrutinizer
Code:
awk ' NF>2{f=$3;$3="B"++b; B=B (B?RS:x) $3 FS f}
      NF>4{f=$5;$5="A"++a; A=A (A?RS:x) $5 FS f}
      NF>6{f=$7;$7="D"++d; D=D (D?RS:x) $7 FS f}
      $1=$1
      END {print B; print A; print D}' infile

Code:
C
H 1 B1
H 1 B2 2 A1
H 1 B3 2 A2 3 D1 0
H 1 B4 2 A3 4 D2 0
B1 1.07000000
B2 1.07000000
B3 1.07000000
B4 1.07000000
A1 109.47120259
A2 109.47120261
A3 109.47123158
D1 120.00001480
D2 119.99999268

print array directly is the skill I learn from your code.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request per second script

Hello; I'm having about 800 log files and i'm trying to write a script that report the counts of lines per second or "requests per second" in each log file and report the output which includes the timestamp for the highest lines per second count and the log file name and the highest number per... (5 Replies)
Discussion started by: Katkota
5 Replies

2. Shell Programming and Scripting

Request to check: compare two files , match same entries, write data before it

Hi all, I have 2 files:Column1 of first file has to be matched with column 3 of second file first file contain DATA like this in 2 columns one with gene name second with whether CAD,HT,RA T2Dor any one column 1 column2 ARFGEF2 CAD DDEF2 CAD PSCD3 CAD PSCD4 CAD CAMK1... (5 Replies)
Discussion started by: manigrover
5 Replies

3. Shell Programming and Scripting

Formatting wget request within script

When using a browser and calling this url .. the data returns the proper range of information ichart dot finance dot yahoo dot com/table.csv?s=YAHOO&a=3&b=14&c=2012&d=03&e=20&f=2012&g=d&ignore.csv (geeze wont let me post url's sorry ) However in my script the formatting is messing up on... (4 Replies)
Discussion started by: harte
4 Replies

4. Shell Programming and Scripting

Shell script request

I've a master file which will contain 100 file names, The script should read file name from a master file and format the file as below in AIX. input file Filename This is a test file Output File Filename|This is a test file Thanks in advance for file in $FileList; do (5 Replies)
Discussion started by: udayakumar
5 Replies

5. Linux

Increasing total data size per file system request for block drivers

Hi All, I am writing a block driver for a 2GB SD card where i get the total amount of data per request as follows: struct request *req; uint card_addr,total_bytes; struct request_queue *rq = BlkDev->queue; req = elv_next_request(rq); .. .. card_addr = req->sector*512;... (1 Reply)
Discussion started by: amio
1 Replies

6. Shell Programming and Scripting

Solaris request script

Hi, In the request script I need to read user input and store to variable to use it later in postinstall script. e.g. LOGDIR=/app/log echo "Please type the Log Directory : (current value: $LOGDIR)" read LOGDIR When asked, if the user enters a value the parameter is ok and I... (2 Replies)
Discussion started by: potro
2 Replies

7. Shell Programming and Scripting

How to send XML data using HTTP Post Request

How to hit HTTP Post Request along with sending XML data to a Remote server through command line utility like wget (or anything else). (0 Replies)
Discussion started by: sandeep reddy
0 Replies

8. UNIX for Advanced & Expert Users

Using a request script

I am creating a package(Solaris10 on sparc) that needs user input. As I understand it, I need to use a request script. My problem is that the value I set in my request script is not visible in my postinstall script. Not sure if I am doing it right. Here is an example request script... (4 Replies)
Discussion started by: Tornado
4 Replies

9. UNIX for Dummies Questions & Answers

unix script http request

Hi everybody, I have a *.vbs file which I want to run automatically. I want to know if there is anyway to implement the given example for e.g "http://255.255.255.55/script.vbs" what I mean is does anyone know how to make an http request from a unix script?? Thanks in advance!!!!!!!!!!! (1 Reply)
Discussion started by: arksal
1 Replies
Login or Register to Ask a Question