Needed shell script to read txt file and do some modification


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Needed shell script to read txt file and do some modification
# 15  
Old 11-22-2012
Dear RudiC..
I had tried with big file in which depth is coming at starting of declaration....might be because of conflict...I am here pasting the same
netcdf \175_phy {
dimensions:
XLON = 6 ;
YLAT = 7 ;
DEPTH = 462 ;
bnds = 2 ;
XIN = 3968 ;
variables:
double XLON(XLON) ;
XLON:units = "degrees_east" ;
XLONSmilieoint_spacing = "even" ;
XLON:axis = "X" ;
XLON:modulo = 360. ;
XLON:standard_name = "longitude" ;
double YLAT(YLAT) ;
YLAT:units = "degrees_north" ;
YLATSmilieoint_spacing = "even" ;
YLAT:axis = "Y" ;
YLAT:standard_name = "latitude" ;
double ZDEPTH(ZDEPTH) ;
LON:history = "From sk175_ctd.csv" ;
double LAT(XIN) ;
LAT:missing_value = -1.e+34 ;
LAT:_FillValue = -1.e+34 ;
LAT:long_name = "V10" ;
LAT:history = "From sk175_ctd.csv" ;

// global attributes:
:history = "FERRET V6.82 21-Nov-12" ;
:Conventions = "CF-1.0" ;
:title = "748_Physical_Data" ;
data:

XLON = 93.4369964599609, 94.4369964599609, 95.4369964599609,
96.4369964599609, 97.4369964599609, 98.4369964599609 ;

YLAT = 12.0030002594, 13.0030002594, 14.0030002594, 15.0030002594,
16.0030002594, 17.0030002594, 18.0030002594 ;

DEPTH = 2, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80,
85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155,
160, 165, 170, 175, 180, 185, 190, 195, 200, 205, 210, 215, 220, 225,
230, 235, 240, 245, 250, 255, 260, 265, 270, 275, 280, 285, 290, 295,
300, 305, 310, 315, 320, 325, 330, 335, 340, 345, 350, 355, 360, 365,
370, 375, 380, 385, 390, 395, 400, 405, 410, 415, 420, 425, 430, 435 ;
TEMP_G =
30.3838383066439, 30.3882053246992, 30.3924360699913, 30.3965465565034,
30.4005514621873, 30.404463453727,
30.374986188776, 30.3796235626175, 30.3841268994998, 30.3885127368018,
30.3927962980837, 30.3969907826882,
30.3656463921024, 30.3705491637335, 30.3753205195448, 30.3799775103733,
30.3845358989906, 30.3890094149276,
30.35582892106, 30.3609916018094, 30.3660258665825, 30.3709492694464,
30.3757781056927, 30.3805266323537,
30.3455445472965, 30.3509611316731, 30.3562526706283, 30.3614372109447,
30.366531573443, 30.371550539739 ;
}

How do I bypass


# 16  
Old 11-22-2012
Please use code tags!

The new sample file you posted is very different to the one we, pamu and myself, were working on. This ruins the solutions: no empty line between records, no TEMPERATURE entry, no SALINITY entry.
How do you expect solutions to work if the data structures they rely on disappear?
# 17  
Old 11-22-2012
whether its possible to attach my txt.file ? here
# 18  
Old 11-22-2012
Use attachments in advanced posting.
# 19  
Old 11-22-2012
Not working with huge file...

Needed variables in column are ZDEPTH,TEMP_G, TEMP_L,SAL_G,SAL,G

see my file...here attached...
# 20  
Old 11-22-2012
This really brings my awk down to its knees! Try this and come back with results:
Code:
awk '{gsub (/[ ;{}\n]/,"")}
     /^ZDEPTH[^_]/ {j=split($2, ZD, /, */); HdZ=$1; if (j>max) max=j}
     /^TEMP_G/     {k=split($2, TG, /, */); HdT=$1; if (k>max) max=k}
     /^TEMP_L/     {l=split($2, TL, /, */); HdL=$1; if (l>max) max=l}
     /^SAL_G/      {m=split($2, SG, /, */); HdG=$1; if (m>max) max=m}
     /^SAL_L/      {n=split($2, SL, /, */); HdS=$1; if (n>max) max=n}
     END {print HdZ, HdT, HdL, HdG, HdS; 
          for (i=1;i<=max; i++) print ZD[i], TG[i], TL[i], SG[i], SL[i]}
    ' FS="[=;]" OFS="\t" RS= file
ZDEPTH  TEMP_G  TEMP_L  SAL_G   SAL_L
2       30.3838383066439        29.9991184776014        32.6905910485831        33.0539176423929
5       30.3882053246992        29.77256752473  32.6878127401931        33.0282461530583
10      30.3924360699913        29.9804910263879        32.685054943924 32.7374162316174
15      30.3965465565034        29.9589844353825        32.6823094722375        32.8266457559109

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

3. Shell Programming and Scripting

Help with shell script - filter txt file full of ips

Hello again gentlemen. I would like to make a shell script to 'optimize' a plain text full of IPs. Let's suppose to have this text file: 1.192.63.253-1.192.63.253 1.0.234.46/32 1.1.128.0/17 1.116.0.0/14 1.177.1.157-1.177.1.157 1.23.22.19 1.192.61.0-1.192.61.99 8.6.6.6 I want to... (2 Replies)
Discussion started by: accolito
2 Replies

4. UNIX for Dummies Questions & Answers

C-Shell script help reading from txt file

I need to write a C-Shell script with these properties: It should accept two arguments on the command line. The first argument is the name of a file which contains a list of names, and the second argument is the name of a directory. For each file in the directory, the script should print the... (1 Reply)
Discussion started by: cerce
1 Replies

5. UNIX for Dummies Questions & Answers

txt file modification which is beyond me

Dear all, I 'd like to create a new txt file using the old file. For example, in old file, if count=2 then in new file, repeat that row twice, with the only difference is: on the first row, 'start' column contains the 1st apart of the 'start' in the old file; while in the 2nd row, the 'start'... (7 Replies)
Discussion started by: forevertl
7 Replies

6. Shell Programming and Scripting

Shell script to send an email from the txt file

Hi Friends, Could you guys help me out of this problem... I need to send an email to all the users and the email has to be picked from the text file. text file contains the no. of records like: giridhar 224285 847333 giridhar276@gmail.com ramana 84849 33884 venkata.ramana@gmail.com... (6 Replies)
Discussion started by: giridhar276
6 Replies

7. Shell Programming and Scripting

Shell Script Needed to Read a text from a list files

Hi, Below is my issue which I desperately need and I want a shell script which can do this job. I need this script as I m planning to put this for a system health check. Please assist me. 1. There are 10 log files in a particular location. 2. open each log file. Goto to the end of the... (4 Replies)
Discussion started by: kashriram
4 Replies

8. UNIX for Dummies Questions & Answers

File comparision and modification using shell script

Hello everyone, I would like to know how to compare two files and modify any differences with some other data using shell script. I think it would be better understood with an example. I got two files named 'filex' and filey'. 'filex' is constant file without any changes in data. 'filey' is... (2 Replies)
Discussion started by: maddy81
2 Replies

9. UNIX for Dummies Questions & Answers

Shell script: last modification date for a file

Hi i have a ques in Shell scripting: ques: accept a filename as a command line argument. Validate the input and display the last modification date for that file. Help pls. (4 Replies)
Discussion started by: onlyc
4 Replies

10. AIX

How to edit txt file by shell script?

What I want to do is just delete some lines from a text file, I know it's easy using copy and redirect function, but what I have to do is edit this file (delete the lines) directly, as new lines may be added to the text file during this period. Can AIX do this ? # cat text 1:line1 2:line2... (3 Replies)
Discussion started by: dupeng
3 Replies
Login or Register to Ask a Question