Put the appropriate value if reached the condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Put the appropriate value if reached the condition
# 1  
Old 05-09-2012
Put the appropriate value if reached the condition

i have a file as below:
Code:
  ? ? ?  ? 20060101  
DHR ? ? ?  ? 20060101 1316 30.90
KOM ? ? ?  ? 20060101 1317 7.20
DHR ? ? ? Pg ? 20060101 1316 27.32
DHR ? ? ? Sg ? 20060101 1316 30.52

  ? ? ?  ? 20060101  
MRD ? ? ?  ? 20060101 1355 46.12
SHB ? ? ?  ? 20060101 1355 40.90
HSH ? ? ? Pn ? 20060101 1354 48.78

I want:
1-delete the lines of each section which start with "?" or the lines which 5th field of them, contains "?".

2-if 5th field of each line contains "Pg" then make new field (9th) and write on it the number "1", if 5th field contains "Pn" write "2" and if contains "Sg" write "3" on new field (9th field)
3-protect blank lines between sections.(very important!)
# 2  
Old 05-09-2012
You are rapidly demanding solutions to your problems. I checked your posts/threads and this is the last code I post to you, before you don't show any own effort.
We help people - that's what the forum is about. But we do not constantly do their work for them. There has to be at least some slight learning effect.
You got plenty of examples on your other posts so it is time to try something yourself and ask here, if you get stuck. This is more the spirit of this forum. It is no Drive-In for scripts.

Code:
# awk '$1 != "?" && $5 != "?" && $1 {if($5 == "Pg"){v=1} if($5 == "Pn"){v=2} if($5 == "Sg"){v=3} print $0,v} /^$/' infile
DHR ? ? ? Pg ? 20060101 1316 27.32 1
DHR ? ? ? Sg ? 20060101 1316 30.52 3

HSH ? ? ? Pn ? 20060101 1354 48.78 2


Last edited by zaxxon; 05-09-2012 at 12:00 PM.. Reason: phrasing
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 05-10-2012
I'm so sorry but believe me I'm trying myself but I'm at the beginning of learning also I'm trying learning Fortran to compare differences between languages, by the way thank you very much, i promise do more effort
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Merge lines until known character reached

Hello all, Hopefully this should be an easy one for you. I have a file that contains a list of parameters and their values. Some of these values are 2D arrays split over several lines, I need to move these so the parameter name and it's full value is all on one line. The parameters are... (5 Replies)
Discussion started by: RobynP
5 Replies

2. UNIX for Dummies Questions & Answers

How to confirm that I've reached the nproc limit?

Hi, I am getting the error su: cannot set user id: Resource temporarily unavailable. In limits.conf, it shows soft nproc 2047 for this user. ps H -u | wc -l shows 508 processes only. Linux flavour is Red Hat Enterprise Linux Server release 5.10 (Tikanga) Any advice will be much... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. UNIX for Advanced & Expert Users

NTP server can not be reached

hello Guys, I have an NTP problem on my SUN N240 server. External NTP server is being used for this box and when i run 'ntpq -p' i get connection refused message; Code: ntpq -p ntpq: read: Connection refused Here this is the ntp.conf file: Code: cat /etc/ntp.conf # BEGIN NTP... (1 Reply)
Discussion started by: dyavuzy1
1 Replies

4. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

5. Shell Programming and Scripting

how can i put the condition in for loop for the below.

i have the equation like below 07:35:07 ( AB : 2319f.ab * 22) + ( AB : 2320f.ab * 22.03 ) + ( AB :2321f.ab * 22.07 ) ...... N i want put ":" as a delimiter and break the equation like below 2319f.ab * 22 2320f.ab *22.03 2321f.ab * 22.07 . . N i know the number of... (1 Reply)
Discussion started by: mail2sant
1 Replies

6. Shell Programming and Scripting

how to put "grep" in the if condition..

i need a favour if ( grep -i adding mpg* | grep -iv equation | ls -ctr | tail -1 ) # if it is not found echo "log couldnot find " else var='grep -i adding mpg* | grep -iv equation | ls -ctr | tail -1' for the above i am struggling with syntax could someone please help me in that (1 Reply)
Discussion started by: mail2sant
1 Replies

7. Shell Programming and Scripting

How to grab the value of field before the line reached

Hi. I have a qury whihc I hope someone could clarify. I have a file:- Num Measure 108 0.05 12 0.45 13 0.2 19 0.5 I wanted to grep the value of 19 from Column Num which will then take the minimum value of measure (not including 19's measure value).... (3 Replies)
Discussion started by: ahjiefreak
3 Replies

8. UNIX for Dummies Questions & Answers

What condition to be put in the while loop?

i have got a file where the env command is appended 5 times. i have to now look for the username and display it in the form of 1) PWD=/home/lee.ballancore 2) USER=lee.ballancore 3) MAIL=/var/spool/mail/lee.ballancore 4) LOGNAME=lee.ballancore 5) HOME=/home/lee.ballancore 6)... (1 Reply)
Discussion started by: nehaquick
1 Replies

9. SCO

cpio: Ulimit reached for file output

I am trying run cpio backing up to tape, but I get the above error. Can anyone assist please as I am sleeping at work today. I tried setting the ulimit to unlimited but when I rebooted the server it came back with another value and I cannot run my backup now.... (0 Replies)
Discussion started by: dustytina
0 Replies

10. Solaris

Max LUN reached ? (Securepath)

Hi all, I can not present a new Lun with my EVA 5000 storage and Securepath ... I have already 16 Lun's presented to the same server (Solaris 8), but can not add the 17th :-( Do you know if we have a limitation with Solaris or Securepath ? (Config file to update, software limits ...) ... (3 Replies)
Discussion started by: unclefab
3 Replies
Login or Register to Ask a Question