Check first specific string after a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check first specific string after a pattern
# 1  
Old 12-20-2017
Check first specific string after a pattern

Hi,

I've a file with content as below

Code:
first_block_list{
a:5
b:3
c:8
}
new_store_list(
a:1000
b:200
c:3343
)
first_item_list{
a:10
b:20
c:30
}
second_item_list{
a:100
b:40
c:100
 {c_a:20,c_b:40,c_c:40}
}
third_item_list{
a:40
{a_a:5,a_b:35}
b:4
c:5
}

Now I want to print the lines based on '_item_list' and then 'b:<value>'.

eg in this is

Code:
first_item_list:20
second_item_list:40
third_item_list:4

Any idea how to do this.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 12-20-2017 at 08:43 AM.. Reason: Added CODE tags.
# 2  
Old 12-20-2017
Would
Code:
awk '/_item_list/ {IL=1; printf "%s", substr ($0, 1, length-1)} IL && /^b:/ {IL=0; printf "%s\n", substr ($0, 2)}' file
first_item_list:20
second_item_list:40
third_item_list:4

come close?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract whole word preceding a specific character pattern with first occurence of the pattern

Hello. Here is a file contents : declare -Ax NEW_FORCE_IGNORE_ARRAY=(="§" ="§" ="§" ="§" ="§" .................. ="§"Here is a pattern =I want to extract 'NEW_FORCE_IGNORE_ARRAY' which is the whole word before the first occurrence of pattern '=' Is there a better solution than mine :... (3 Replies)
Discussion started by: jcdole
3 Replies

2. UNIX for Dummies Questions & Answers

Search specific string logfile specific date range

Hi, I have logfile like this.. === 2014-02-09 15:46:59,936 INFO RequestContext - URL: '/eyisp/sc/skins/EY/images/pickers/comboBoxPicker_Over.png', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko': Unsupported with Accept-Encoding header === 2015-02-09... (8 Replies)
Discussion started by: kishk
8 Replies

3. UNIX for Dummies Questions & Answers

Search for a specific String in a log file for a specific date range

Hi, I have log file which rolls out every second which is as this. HttpGenRequest - -<!--OXi dbPublish--> <created="2014-03-24 23:45:37" lastMsgId="" requestTime="0.0333"> <response request="getOutcomeDetails" code="114" message="Request found no matching data" debug="" provider="undefined"/>... (3 Replies)
Discussion started by: karthikprakash
3 Replies

4. Shell Programming and Scripting

Replace string in line below specific pattern?

Hi, I'm trying to replace a string with sed, in a text file containing this pattern: location alpha value x location beta value y location gamma value y location delta value y location theta value z ... What I want to achieve is: Find location beta into text file... (1 Reply)
Discussion started by: TECK
1 Replies

5. UNIX for Dummies Questions & Answers

Check for entry of specific pattern

Hey Guys and Gals, I am having trouble with what I thought shouldn't be hard.. In a script I am working on there is a need to enter a MAC address. MAC addresses are formatted ; XX:XX:XX:XX:XX:XX where X can be 0-9, a-f or A-F So in the sample script the query is something... (4 Replies)
Discussion started by: TAPE
4 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. UNIX for Dummies Questions & Answers

How to Detect Specific Pattern and Print the Specific String after It?

I'm still beginner and maybe someone can help me. I have this input: the great warrior a, b, c and what i want to know is, with awk, how can i detect the string with 'warrior' string on it and print the a, b, and c seperately, become like this : Warrior Type a b c Im still very... (3 Replies)
Discussion started by: radynaraya
3 Replies

8. Shell Programming and Scripting

Find and replace a string a specific value in specific location in AIX

Hi, I have following samp.txt file in unix. samp.txt 01Roy2D3M000000 02Rad2D3M222222 . . . . 10Mik0A2M343443 Desired Output 01Roy2A3M000000 02Rad2A3M222222 . . (5 Replies)
Discussion started by: techmoris
5 Replies

9. Shell Programming and Scripting

Concatenating and appending string based on specific pattern match

Input #GEO-1-type-1-fwd-Initial 890 1519 OPKHIJEFVTEFVHIJEFVOPKHIJTOPKEFVHIJTEFVOPKOPKHIJHIJHIJTTOPKHIJHIJEFVEFVOPKHIJOPKHIJOPKEFVEFVOPKHIJHIJEFVHIJHIJEFVTHIJOPKOPKTEFVEFVEFVOPKHIJOPKOPKHIJTTEFVEFVTEFV #GEO-1-type-2-fwd-Terminal 1572 2030... (7 Replies)
Discussion started by: patrick87
7 Replies

10. Shell Programming and Scripting

using sed to replace a specific string on a specific line number using variables

using sed to replace a specific string on a specific line number using variables this is where i am at grep -v WARNING output | grep -v spawn | grep -v Passphrase | grep -v Authentication | grep -v '/sbin/tfadmin netguard -C'| grep -v 'NETWORK>' >> output.clean grep -n Destination... (2 Replies)
Discussion started by: todd.cutting
2 Replies
Login or Register to Ask a Question