Parsing file, yaml file? Extracting specific sections


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing file, yaml file? Extracting specific sections
# 1  
Old 01-22-2009
Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl or high level scripting language.

This is actually from /var/cpanel/userdata/username/main

Code:
---
addon_domains:
  somedomain.com: mysubdomain.primarydomain.com
  somedomain2.com: mysubdomain2.primarydomain.com
  somedomain3.com: mysubdomain3.primarydomain.com
cp_php_magic_include_path.conf: 0
main_domain: primarydomain.com
parked_domains: []

sub_domains:
  - mysubdomain.primarydomain.com
  - mysubdomain2.primarydomain.com
  - mysubdomain3.primarydomain.com

# 2  
Old 01-22-2009
Given a sample input above, what would be the desired output?
# 3  
Old 01-22-2009
If split by :, it would be the first field under addon_domains, until cp_php_magic_include_path.conf: 0 was reached.

Code:
somedomain.com
somedomain2.com
somedomain3.com

# 4  
Old 01-22-2009
something along these lines - assuming ''somedomain-s' are indented with spaces.

nawk -f rh.awk myYAMLfile

rh:awk:
Code:
BEGIN {
   FS=RS=""
}
$1 == "addon_domains:"{
   for(i=2; $i ~ /^  */; i++)
      print substr($i, 1, index($i, ":")-1)
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Help on parsing Oracle RMAN output for string and print sections of a file

Hi, I need some advise on how to print 'sections' of the attached file. I am searching for some that says Marked Corrupt and print some lines after it. At the moment I am running the command below: sed -n -e '/Marked Corrupt/{N;N;p;}' rman_list_validate.txtThis gives me the following... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Shell Programming and Scripting

YAML file update

removing post since it got fix (1 Reply)
Discussion started by: kishore150
1 Replies

3. UNIX for Advanced & Expert Users

Extracting specific lines from data file

Hello, Is there a quick awk one-liner for this extraction?: file1 49389 text55 52211 text66 file2 59302 text1 49389 text2 85939 text3 52211 text4 13948 text5 Desired output 49389 text2 52211 text4 Thanks!! (5 Replies)
Discussion started by: palex
5 Replies

4. Shell Programming and Scripting

Extracting content from a file in specific format

Hi All, I have the file in this format **** Results Data **** Time or Step 1 2 20 0.000000000e+00 0s 0s 0s 1.024000000e+00 Us 0s 0s 1.100000000e+00 1s 0s 0s 1.100000001e+00 1s 0s 1s 2.024000000e+00 Us Us 1s 2.024000001e+00 ... (7 Replies)
Discussion started by: diehard
7 Replies

5. Shell Programming and Scripting

extracting specific lines from a file

hi all, i searched in unix.com and accquired the following commands for extracting specific lines from a file .. sed -n '16482,16482p' in.sql > out.sql awk 'NR>=10&&NR<=20' in.sql > out.sql.... these commands are working fine if i give the line numbers as such .. but if i pass a... (2 Replies)
Discussion started by: sais
2 Replies

6. Shell Programming and Scripting

SED 4.1.4 - INI File Change Problem in Variables= in Specific [Sections] (Guru Help)

GNU sed version 4.1.4 on Windows XP SP3 from GnuWin32 I think that I've come across a seemingly simple text file change problem on a INI formatted file that I can't do with SED without side effects edge cases biting me. I've tried to think of various ways of doing this elegantly and quickly... (5 Replies)
Discussion started by: JakFrost
5 Replies

7. Shell Programming and Scripting

Extracting specific text from a file

Dear All, I have to extract a a few lines from a log file and I know the starting String and end string(WHich is same ). Is there any simplere way using sed - awk. e.g. from the following file -------------------------------------- Some text Date: 21 Oct 2008 Text to be extracted... (8 Replies)
Discussion started by: rahulkav
8 Replies

8. Programming

problems iterating in RUBY while extracting info from YAML, Pls help!

Hi all, I am stuck with a ruby script that extracts detials from yaml file and processes accordingly. the yaml file confivnic: device: vnic1: policy: - L2 mode: active vnic2: policy: - L3 - L4 mode: active type: aggr ... (1 Reply)
Discussion started by: wrapster
1 Replies

9. UNIX for Dummies Questions & Answers

Is extracting specific files from a zip file possible?

If a zip file contains several zip files, but if the file names of the files needed are known, is there a variation of the unzip command that will allow those few (individual) files to be extracted? --- Example: Zip file name: zip.zip unzip -l zip.zip will display file01, file02, file03, etc.... (1 Reply)
Discussion started by: HLee1981
1 Replies

10. Shell Programming and Scripting

Parsing file and extracting the useful data block

Greetings All!! I have a very peculiar problem where I have to parse a big text file and extract useful data out of it with starting and ending block pattern matching. e.g. I have a input file like this: sample data block1 sample data start useful data end sample data block2 sample... (5 Replies)
Discussion started by: arminder
5 Replies
Login or Register to Ask a Question