Extract a value using sed (easy)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract a value using sed (easy)
# 1  
Old 03-20-2015
Extract a value using sed (easy)

I have this command to replace the version value from PROGRAM (for example here PROGRAM == player) by NEWVERSION

Code:
sed "/^ *$PROGRAM:/{N; s/[^:]*$/ $NEWVERSION/;}" -i $PRDFILE

Code:
  player:
    version: V6R2013xD3HF5v1
  player_old:
    version: V6R2013xD3HF5v1
  partchecker:
    version: 6.142.1-rc6

But now, I would like just extract PROGRAM Version without replacing the string.
(Just get V6R2013xD3HF5v1 if program == player)

Thank you for your help
# 2  
Old 03-20-2015
Try
Code:
sed -n "/^ *$PROGRAM:/{n;p}" file
    version: V6R2013xD3HF5v1

or, if "version:" also should disappear, try
Code:
sed -n "/^ *$PROGRAM:/{n;s/^ *version: //;p}" file
V6R2013xD3HF5v1


I strongly recommend reading man sed!
This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-20-2015
I will do it this week-end, I swear Smilie

Thanks !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Couple of easy questions for experts on awk/sed

Hello Experts.. I have 3-4 C codes with Oracle SQL statements embedded. All the SQL statements starts with EXEC SQL keyword and ends with ;. I want to extract all the SQL statements out of these codes. I did awk '/^EXEC SQL/,/\;/' inputFile (I use this on all of the codes individually). That... (2 Replies)
Discussion started by: juzz4fun
2 Replies

2. Shell Programming and Scripting

sed to extract all strings

Hi, I have a text file containing 2 lines as follows: I'm trying to extract all the strings following an "AME." The output would be as follows: BUSINESS_UNIT PROJECT_ID ACTIVITY_ID RES_USER1 RESOURCE_ID_FROM ANALYSIS_TYPE BI_DISTRIB_STATUS BUSINESS_UNIT PROJECT_ID ACTIVITY_ID... (5 Replies)
Discussion started by: simpletech369
5 Replies

3. Shell Programming and Scripting

sed data extract

Hello, I have huge number files in a directory. All files have the data. I want extract data. I want all output write to single csv file. following codes works. Thank you very much for help. sed -n '/.*Content$txtE_Zip" type="text" value="\(*\)" maxlength.*/s//\1/p' *>file1 sed -n... (5 Replies)
Discussion started by: hoo
5 Replies

4. Shell Programming and Scripting

Extract using sed

Given a file with contents /arch/powerpc/boot/4xx.o > /arch/powerpc/boot/.4xx.o.cmd > /arch/powerpc/boot/addnote 5766a5769 > /arch/powerpc/boot/.addnote.cmd 5768a5772,5773 > /arch/powerpc/boot/bamboo.o > /arch/powerpc/boot/.bamboo.o.cmd 5769a5775,5778 > /arch/powerpc/boot/cpm-serial.o... (8 Replies)
Discussion started by: xerox
8 Replies

5. Shell Programming and Scripting

Extract word using sed

Hello, I am new to sed and am trying to extract a word using sed. for example i have a line "const TotalAmount& getTotalAmount() const; " in the file test.txt I am trying to extract getTotalAmount() from the line. For this i tried cat test.txt | sed -n 's/.*get*\(\)//p But... (8 Replies)
Discussion started by: prasbala
8 Replies

6. Shell Programming and Scripting

Easy unix/sed question that I could have done 10 years ago!

Hi all and greetings from Ireland! I have not used much unix or awk/sed in years and have forgotten a lot. Easy enough query tho. I am cleansing/fixing 10,000 postal addresses using global replacements. I have 2 pipe delimited files , one is basically a spell checker for geographical... (4 Replies)
Discussion started by: dewsbury
4 Replies

7. Shell Programming and Scripting

SED to extract characters

Hi, Please let me know how do we write a piece of code to extract characters from a line using SED. (2 Replies)
Discussion started by: Shilpi
2 Replies

8. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies

9. UNIX for Dummies Questions & Answers

Easy sed question?

I have a line like: "Jun 19 12:56:22 routername 45454:" I want to keep all information except the seconds of the time. I tried: sed 's/..:..:../..:../g' but apparently I'm on the wrong track, because although that matches on the time, it replaces it with the literal ..:.. How... (6 Replies)
Discussion started by: earnstaf
6 Replies

10. Shell Programming and Scripting

Please help! Sed extract a pattern

I am trying to extract "securitySettings" out of line: <a ref ="http://localhost:5654/securitySettings"> using sed as follows: name = `grep "localhost" file.html | sed -n 's/.**\/\(.*)/\">/\1/p'` But it didn't run, seems have some syntax error. Do anybody knows why? Thank you very... (11 Replies)
Discussion started by: zhen
11 Replies
Login or Register to Ask a Question