capturing the value in file before string(*) and the similar value in next line only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting capturing the value in file before string(*) and the similar value in next line only
# 1  
Old 02-01-2012
capturing the value in file before string(*) and the similar value in next line only

I've the output in the file like below. I want to capture the value in file before string(*) and the similar value in next line only.
Code:
cat test1.txt
 
0003  Not Visible             (M)     0   00  03F
0005  Not Visible             (M)     0   00  040
-     AVAILABLE                       0   00  041 *
000B  Not Visible             (M)     0   00  043
000F  Not Visible             (M)     0   00  044
0011  Not Visible             (M)     0   00  045
0013  Not Visible             (M)     0   00  046
0015  Not Visible             (M)     0   00  047
0017  Not Visible             (M)     0   00  048
0019  Not Visible             (M)     0   00  049
001B  Not Visible             (M)     0   00  04A
001D  Not Visible             (M)     0   00  04B
001F  Not Visible             (M)     0   00  04C
0121  Not Visible             (M)     0   00  04D
0123  Not Visible             (M)     0   00  04E
0125  Not Visible             (M)     0   00  04F
0127  Not Visible             (M)     0   00  050
0129  Not Visible             (M)     0   00  051
012B  Not Visible             (M)     0   00  052
      AVAILABLE                       0   00  053 
0135  Not Visible             (M)     0   00  054
0153  Not Visible             (M)     0   00  055
-     AVAILABLE                       0   00  056 *
016B  Not Visible             (M)     0   00  057
017D  Not Visible             (M)     0   00  058
004F  Not Visible             (M)     0   00  059
0235  Not Visible             (M)     0   00  05A
-     AVAILABLE                       0   00  05D *
0465  Not Visible             (M)     0   00  06A
 -    AVAILABLE                       0   00  100 *
    Total                  ----
    Mapped Devices:         130
    Including Metamembers:  230
    Available Addresses:   1679 (s)

Legend for Available address:
(*): The VBUS, TID, LUN address values represent a gap in the
     address assignments or are the next available address in
     the run
(s): The Available Addresses for a director are shared among
     its ports (shared)

In this example, I am looking for the below output
Code:
041
043
056
057
05A
06A
100


Last edited by Franklin52; 02-01-2012 at 05:26 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 02-01-2012
This works for me..


Code:
$ awk '$NF=="*" {print $(NF-1);getline;print $NF}' file
041
043
056
057
05D
06A
100
----
$

This would also print the "---" line. hope it doesn't bother you much.
This User Gave Thanks to clx For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

2. Shell Programming and Scripting

Search a string in a text file and add another string at the particular position of a line

I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB and add/replace... (1 Reply)
Discussion started by: suryanarayana
1 Replies

3. Shell Programming and Scripting

capturing the value in file before string(*) using sed

I am trying to capture the last value before the the * in test4.txt file using sed & tail (in this case 0FA). I got the output using the below steps. P.s: The number of * in the file varies from file to file. Any idea of a better way to do this? cat test4.txt ... (2 Replies)
Discussion started by: sai_1712
2 Replies

4. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

5. Red Hat

Help for capturing a URL from a line from large log file

Can someone please help me how do I find a URL from lines of log file and write all the output to a new file? For e.g - Log file has similar entries, 39.155.67.5 - - "GET /abc/login?service=http://161.120.36.39/CORPHR/TMA2007/default.asp HTTP/1.1" 401 3218 54.155.63.9 - - "GET... (2 Replies)
Discussion started by: rockf1bull
2 Replies

6. Shell Programming and Scripting

Searching String from set of similar File pattern from the Dir

Guys, Here is the script that searches string from the set of similar files from the log directory, All the file patterns are defined as input file, from where the script should map to those files in the LOG_DIR and should start searching the strings from all those similar files. ... (1 Reply)
Discussion started by: raghunsi
1 Replies

7. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

8. Shell Programming and Scripting

merging similar columns in a single line file

Hi Guys. I have tried the commands sort and join. But I couldn't able to to find the command for joining in a single line based on keys.My example inputs and outputs are like the following. Help would be appreciated.:D Input file a1tabXXXXXXX a2tabXXXXXXX a6tabYYYYYYYYY a71tabXXXXXXX... (7 Replies)
Discussion started by: repinementer
7 Replies

9. Shell Programming and Scripting

capturing line from script output and appending to a file

Hi all, I did some searching in this forum but can't find anything that matches the issue I'm bumping heads with. On a CentOS4/Postfix (and bash everywhere) mail gateway box I run a command periodically to purge the Postfix queue of messages "From:MAILER-DAEMON". This is the one line'r... (6 Replies)
Discussion started by: wally_welder
6 Replies
Login or Register to Ask a Question