Can any programmer do this task in shell script...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can any programmer do this task in shell script...
# 1  
Old 11-23-2012
Can any programmer do this task in shell script...

input file's one set header is this,
Code:
----------------------------------------------------- 
 OUTPUT FROM ASCII FILE: CAST #1 
----------------------------------------------------- 
 
 CC  Cruise Latitude Longitude YYYY MM DD  Time Cast    #Levels 
 CA    8504   50.083  -144.883 1970  1  2 18.70  3319677   70 
 
 
      z             1               2             
 
     0.0 (1) [00]  5.900 (3) [00] 32.580 (5) [00] 
    10.0 (2) [00]  5.900 (3) [00] 32.580 (5) [00] 
    20.0 (2) [00]  5.900 (3) [00] 32.580 (5) [00]

the out put file's header will look like,

Code:
Cast  CC  Cruise  Latitude  Longitude  YYYY  MM  DD  Time  Cast  #Levels           z             1               2               3

Needed columns

Cast_No
CC
Cruise
Latitude
Longitude
YYYY
MM
DD
Time
Cast
#Levels
z
z_quality
z_quality1
1 ---------------------z value (here its 0,10 and 20)
1_quality ---------its (1),(2) and (3)
1_quality_1 ------its [00], [00], and [00]
2
2_quality
2_quality_1


As you see here, 3 is an additional column, which exists for some datasets and is missing for others. So this
header has to be constructed only once. i.e. at the beginning point. In order to keep track whether the header is constructed at least once, we need to make use of flag "_onceFlag" which is set to false initially. When header is constrcuted first time, and is written in the output file, _onceFlag is set to true and next time it won't write header information in the output file.

Time being I am using C++ program to do this task, problem is I need to enter file name every time...

So if any one can help to do this task, it will be helpful...

- Thanks in advance...

- Akshay

Last edited by Scrutinizer; 11-23-2012 at 03:43 PM.. Reason: to give complete description about the task; mod: code tags
# 2  
Old 11-23-2012
what you tried so far ?
# 3  
Old 11-23-2012
Looking at the Output_needed_format.txt file and looking at the 1st 9 lines, I thought I saw a pattern and knew what you wanted. But, the last 9 lines (not exactly corresponding to the #Levels value 10 and having no data in the z* columns and the 1* columns in the output) don't make any sense to me.

If you want our help on this, please post the complete output that you want to get from the following entries in Input.txt:
Code:
 OUTPUT FROM ASCII FILE: CAST #1
 OUTPUT FROM ASCII FILE: CAST #2
 OUTPUT FROM ASCII FILE: CAST #3
and
 OUTPUT FROM ASCII FILE: CAST #50

and answer a few questions:
  1. The input records have data in columns with headers z, 1, 2, and 3. Does the code we supply need to make a pass through the input for the exact set of fields supplied in the files to be processed, or should the code always assume there are just the above four sets of data included in Input.txt?
  2. Does the code need to reformat floating point values to remove trailing zeros, or can it just print the values found in the input?
  3. When printing floaing point values, do the decimal points need to line up?
  4. Does the code need to verify that the #Levels field value exactly matches the number of data lines after the z header line? If so, what should be done if there is a mismatch? Should the code make any other data validity checks? If so, what checks and what should be done if the checks fail?
# 4  
Old 11-25-2012
You may want to go composing your own script (esp. formatting...) starting from this one:
Code:
awk     '/CAST/{Cnr=substr($6,2);getline;getline;getline;getline;DS=$0}
         /^$/{next}
         /^      z/,/^ ERR:/{if ($1~/^ *z|^ *ERR:/) next; $1=$1;print Cnr, DS, $0}
        ' OFS="\t" Input.txt
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 0.0     (1)     [00]-99.990     (0)     [00]    2.160   (3)     [00] 
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 37.0    (2)     [00]    -1.850  (3)     [00]    34.420  (4)     [00] 
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 64.0    (2)     [00]    -1.900  (3)     [00]    34.380  (4)     [00] 
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 110.0   (3)     [00]    -1.850  (3)     [00]    34.400  (4)     [00] 
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 165.0   (3)     [00]    -1.850  (3)     [00]    34.380  (4)     [00] 
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 220.0   (3)     [00]    -1.850  (3)     [00]    34.420  (4)     [00]
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 274.0   (3)     [00]    -1.850  (3)     [00]    34.400  (4)     [00]
1        DE   10499  -66.030    89.630 1903  1  3 9999.00  9381985    8 348.0   (3)     [00]    -1.850  (3)     [00]    34.380  (4)     [00]
2        SU    7966   69.202    33.470 1903  1  7 9999.00  6487310   10 0.0     (1)     [00]    0.960   (2)     [00]
2        SU    7966   69.202    33.470 1903  1  7 9999.00  6487310   10 5.0     (1)     [00]    1.000   (3)     [00]
2        SU    7966   69.202    33.470 1903  1  7 9999.00  6487310   10 10.0    (2)     [00]    1.000   (3)     [00]

It depends heavily on your file structure, so don't complain if it does not work on files different from your input sample...
# 5  
Old 12-02-2012
What you said is right it works only for the sample file which I had given...when I tried with some other file got some error..see

awk: cmd. line:4: fatal: cannot open file `input.txt' for reading (No such file or directory)
# 6  
Old 12-02-2012
Quote:
Originally Posted by Akshay Hegde
What you said is right it works only for the sample file which I had given...when I tried with some other file got some error..see

awk: cmd. line:4: fatal: cannot open file `input.txt' for reading (No such file or directory)
This just says that input.txt is not where it is expected to be. Adapt the path and filename.
If your working file is different from your sample file, you should not be surprised that the proposal provided does not work. Pls. give a meaningful sample in the first place.
# 7  
Old 12-02-2012
experts....have a look on my code,,,I need it in shell scripting...

Hi experts,,


Here I have attached my code just change the extension to cpp and run, you will get output file....that actually I want in shell script...

what script has to do is it should ask latitude and longitude only once, and it has to process all the files in a directory, in my current c++ code every time I am entering latitude and longitude, and file name, I hope you experts can do this task in shell...

Thanks in advance

Akshay
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need list of input and output parameter of task in a text file, using shell script

//file begin ===== //some code task abcd_; input x; input y,z; //some comment output w; //some comment reg p; integer q; begin //some code end endtask : abcd_ //some code //file end ===== expected output from above... (1 Reply)
Discussion started by: rishifrnds
1 Replies

2. Shell Programming and Scripting

Script for database task.

Hi, I need help in creating script for "User password reset in database" by logging into database from linux server and resetting the user password. Could you please provide the script for this task? Steps are given below. 1. Login into database from server sqlplus... (5 Replies)
Discussion started by: Maddy123
5 Replies

3. Shell Programming and Scripting

Whether Shell script can do this task ???

In following attached 748phy.xls file, fifth column is ST_Date, which contains time and dates in this format 22-11-2012 7:54:54 PM in single column I want it to split in this format either 1st column 22/11/2012 and in second column 7:54:54 PM Or like this in separate... (13 Replies)
Discussion started by: Akshay Hegde
13 Replies

4. Shell Programming and Scripting

command task script

ksh $CODE/dis/scripts/IS_BTEQ_LZ_TABLE_AUDIT.sh DIS_BTEQ LZ_DIS_LOAD_LOG_KEY > $CODE/dis/logs/lz_table_audit_`date '+%Y%m%d_%H%M%S'`.log 2>&1 Can some one tell me what the above script is doing? As per my understanding we are executing the script and sending the output to a log file. The... (4 Replies)
Discussion started by: karthikkasarla
4 Replies

5. Homework & Coursework Questions

Shell scripting task

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi all, I am new to shell scripting. And I have a task to do, I tried all possible ways to solve this, but... (8 Replies)
Discussion started by: Strongid
8 Replies

6. Shell Programming and Scripting

Shell scripting task

Hi all, I am new to shell scripting. And I have a task to do, I tried all possible ways to solve this, but didn't. Iwas wondering maybe someone could help me. So I have a random file something like this Andrew John Mike Alfa Omega Beta And I need to create scrip witch would filter any... (1 Reply)
Discussion started by: Strongid
1 Replies

7. Shell Programming and Scripting

last task for my script

hi, infile- create table salary ( occupation_code char(40), earnings decimal(10,2), occ_yearend integer ); outfile- salary:create table salary salary:( occupation_code char(40), salary: earnings decimal(10,2), salary: occ_yearend integer salary:); Thanks. (4 Replies)
Discussion started by: dvah
4 Replies

8. Shell Programming and Scripting

BrainBench Certified Shell Programmer..Any1

Hi I am looking for some one who is Brainbench Certified Shell Programmer, who can share his/her experience. Actually I am planning to give exam, but before that wuld lik some1 to throw light on this..also if dumps are availble pls mail me @ niceboykunal123@gmail.com Thanks & Regards,... (1 Reply)
Discussion started by: niceboykunal123
1 Replies

9. Shell Programming and Scripting

comment and Uncomment single task out of multiple task

I have a file contains TASK gsnmpproxy { CommandLine = $SMCHOME/bin/gsnmpProxy.exe } TASK gsnmpdbgui { CommandLine = $SMCHOME/bin/gsnmpdbgui.exe I would like to comment and than uncomment specific task eg TASK gsnmpproxy Pls suggest how to do in shell script (9 Replies)
Discussion started by: madhusmita
9 Replies

10. Shell Programming and Scripting

Optimized way of doing the task in shell programming

Hi I have a file consists of the following similar lines (10 mb file) 2008-05-15 02:15:38,268 RMSConnectionFactory - Setting session state for connection. 2008-05-15 02:15:38,277 RMSConnectionFactory - Returning WS connection. My task is to find out any missing second lines for... (14 Replies)
Discussion started by: pcjandyala
14 Replies
Login or Register to Ask a Question