How to extract previous value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to extract previous value
# 1  
Old 03-08-2011
How to extract previous value

Hi All,

I am just trying to write a small script which will take the following output as input, and then search for the 'State' value which is not equal to 0x0000, and then will give me output of respective 'Name'.
Code:
 Name                                 = SYSPACE
 State                                = 0x0000
 Name                                 = DEFAULT
 State                                = 0x2000
 Name                                 = CONTROL
 State                                = 0x0000

The output of above should give me DEFAULT, as it's State is not matching with 0x0000.

Please help me. Thanks Naresh

Last edited by Franklin52; 03-08-2011 at 03:55 AM.. Reason: Please use code tags
# 2  
Old 03-08-2011
Code:
awk -F"=" '{if($1 ~ /Name/){name=$2;next;}if($2 ~ /0x0000/)name=0;if(name !=0)print name;}' output

# 3  
Old 03-08-2011
Code:
awk '$1=="State" && $3!~"0x0000"{print x}{x=$3}' file

# 4  
Old 03-08-2011
Code:
sed -n '/Name/,/State/{N;/\n.*0x2000/s/Name = \(.*\)\n.*/\1/p}'

DEFAULT

or awk:
Code:
awk -v RS="Name = " -v FS="\n" '/0x2000/{print $1}'
DEFAULT


Last edited by yinyuemi; 03-08-2011 at 03:58 AM..
# 5  
Old 03-08-2011
This seems the best solution

Code:
awk '$1=="State" && $3!~"0x0000"{print x}{x=$3}'

anyone knows what does 1 stands for ?

awk '$1=="State" && $3!~"0x0000"{print x}{x=$3}1'
# 6  
Old 03-08-2011
Quote:
Originally Posted by dinjo_jo
This seems the best solution

Code:
awk '$1=="State" && $3!~"0x0000"{print x}{x=$3}'

anyone knows what does 1 stands for ?

awk '$1=="State" && $3!~"0x0000"{print x}{x=$3}1'
But there is no "1" at the end of my code...
# 7  
Old 03-08-2011
No but i'm asking that since i see a lot of them using it whats its significance is it for only first time ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract row grater than 3 from previous value of a field

Hi, I am trying to extract data where first field unique value and 4th field of next row is grater than first row 4th field. input data is a below: 7035719974,20-jul-2016 07:42:51,07:42:51,074251,1 7035719974,20-jul-2016 07:43:57,07:43:57,074357,2 7399206761,20-jul-2016... (2 Replies)
Discussion started by: rramkrishnas
2 Replies

2. UNIX for Dummies Questions & Answers

AIX UNIX - script on how to extract from log file with previous date

Hello, I am new to this forum so any assistance would help. I am currently trying to develop a script that extract all data from a log file with has the previous day's date. $ <root@aixtest3> /var/log > more sudo.log May 13 10:52:10 aixtest3 local2:notice sudo: tbrath : TTY=unknown ; ... (14 Replies)
Discussion started by: Kslew82
14 Replies

3. Shell Programming and Scripting

Print previous (non zero)

Dear All, I have file like this, 13819 32.07 1877.65 0 481.81 2100.86 0 789.35 2274.05 0 4627.61 4421.36 0 5831.52 4855.50 20844 38.68 1902.15 0 291.02 1945.88 0 452.57 2013.94 0 2194.28 ... (6 Replies)
Discussion started by: attila
6 Replies

4. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

5. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

6. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

7. Shell Programming and Scripting

To get the previous 5 minutes

Hi I need to get the previous 5 minutes from the currnet time as given below. Please help. Current time : date +%d-%m-%Y_%H-%M output : 16-05-2012_15-05 I need the previous 5 minutes of the above output , Required output: 16-05-2012_15-04 16-05-2012_15-03... (4 Replies)
Discussion started by: Kanchana
4 Replies

8. Shell Programming and Scripting

How to get previous date

Hello, Apologies for not following the forum rules. I will follow it from now on. What I need now is to get the previous date in PERL. Today is 07/01/2010...and the prev date is 06/30/2010. Could you please show me the (localtime) syntax of how to write this so it works in all... (3 Replies)
Discussion started by: nurani
3 Replies

9. Forum Support Area for Unregistered Users & Account Problems

previous posts

Hi, is there a way I can display my previous question posted? I've had a look around but couldn't find anything. Thanks in advance, Simon. (2 Replies)
Discussion started by: james6
2 Replies

10. HP-UX

Previous command

Hi, i would like to retrieve (only retrieve, not execute) a previous command which i executed on the command prompt. I tried the 'up arrow' key, but its not working. Instead,it showed me some funny characters. I searched around and i found the way to do it was using the way below. Several... (5 Replies)
Discussion started by: new2ss
5 Replies
Login or Register to Ask a Question