Sponsored Content
Full Discussion: Parsing a file in bash
Top Forums UNIX for Advanced & Expert Users Parsing a file in bash Post 302910597 by ramky79 on Friday 25th of July 2014 02:43:49 PM
Old 07-25-2014
Parsing a file in bash

Hello All,
I have the following input file that i'm trying to parse:
HTML Code:
10.0.011.40
hadoop 15526 15524 0
hadoop 15528 15526 0
hadoop 19747 4018 1
10.0.081.227
hadoop 2862 2861 0
hadoop 2864 2862 0
hadoop 12177 14376 1
I'm trying to get this in my output file:
HTML Code:
10.0.011.40 15526 15528 19747
10.0.081.227 2862 2864 12177
I have tried this code:
HTML Code:
#!/usr/bin/bash
#set -x
while read line
do
  if [[ $line =~ ^[0-9] ]];then
    IPADDR=`echo "$line" | awk --posix '{if ($1 ~ /^[0-9]/) print $1}'`
  else
    PID=`echo "$line" | awk '{ print $2 }'`
  fi
  IPADDR+=($PID)
  echo ${IPADDR[@]} > ex2
done < ex1
The problem;
I have more than 1 PID rows ( hadoop rows, for each server)

Last edited by ramky79; 07-25-2014 at 04:08 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

2. Shell Programming and Scripting

Help parsing filename with bash script

Hi all! Looking for some help parsing filenames in bash. I have a directory full of files named "livingroom-110111105637.avi". The format is always date and time (yymmddhhmmss). I'm looking to parse the filenames so they are a little more easily readable. Maybe rename them to... (4 Replies)
Discussion started by: mtehonica
4 Replies

3. Shell Programming and Scripting

Parsing (Bash)

Hello, I need help. I create www page, and I have link, where is weather and is updated each hour. And I need cut only weather from source code. Example: Monday : 12/14 ... Can you help me? Thanks (2 Replies)
Discussion started by: krcek12
2 Replies

4. Shell Programming and Scripting

parsing a config file using bash

Hi , I have a config _file that has 3 columns (Id Name Value ) with many rows . In my bash script i want to be able to parse the file and do a mapping of any Id value so if i have Id of say brand1 then i can use the name (server5X) and Value (CCCC) and so on ... Id Name ... (2 Replies)
Discussion started by: nano2
2 Replies

5. Shell Programming and Scripting

Looking for help with parsing file contents in bash [newbie]

Hi I'm just messing around with bash and trying to learn it because I have a course next semester dealing with OS design where we need to know how to use SSH client and either bash or ksh. I've never done shell scripting before. I just started today and I was wondering how parsing files... (1 Reply)
Discussion started by: mehungry
1 Replies

6. Shell Programming and Scripting

BASH parsing for html tags

Hello can anyone help me parse this line. <tr><td>United States of America</td><td>Dollar</td><td>43.309</td></tr><tr><td>Japan</td><td>Yen</td><td>0.5579</td></tr> the line above did not break. so i would like to have a result like this United States of America Dollar 43.309 Japan... (3 Replies)
Discussion started by: doomsayer16
3 Replies

7. Shell Programming and Scripting

Column parsing in a bash script - HELP

I would like to setup a script that pulls in time/date in two seperate columns, and then name the other columns as listed below: Column1=Art/TJ output Column2=Art/TJ output Column3=TJ output column4=Art output Column5=If time/date past 12:00 noon -fail Colume6=If time/date before... (1 Reply)
Discussion started by: walnutpony123
1 Replies

8. Shell Programming and Scripting

Bash script not parsing file with spaces in path

Hi everyone, I'm trying to write my first ever shell script, the OS is Raspbian. The code I have written must be executed whenever a certain database has been modified. The database resides on a Windows server to which I have a mount point, and I have no control over the Windows server at all so... (2 Replies)
Discussion started by: gjws
2 Replies

9. Shell Programming and Scripting

Parsing and Editing a json file with bash script

I am trying to automate editing of a json file using bash script. The file I initially receive is { "appMap": { "URL1": { "name": "a" }, "URL2": { "name": "b" }, "URL3": { "name": "c" }, } WHat I would like to do is replace... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

10. Shell Programming and Scripting

Parsing to_addr field in bash

Hi there, I'm trying to parse the to_addr field of emails and split it into individual email addresses. The idea is to split using the comma character (,): These two first approach work: $ field="'Paul FOO' <paul@foo.com>, Andrew FOO <andrew@foo.com>" $ IFS=, read -r -a array <<< "$field";... (4 Replies)
Discussion started by: chebarbudo
4 Replies
HTML::Filter(3pm)					User Contributed Perl Documentation					 HTML::Filter(3pm)

NAME
HTML::Filter - Filter HTML text through the parser NOTE
This module is deprecated. The "HTML::Parser" now provides the functionally of "HTML::Filter" much more efficiently with the the "default" handler. SYNOPSIS
require HTML::Filter; $p = HTML::Filter->new->parse_file("index.html"); DESCRIPTION
"HTML::Filter" is an HTML parser that by default prints the original text of each HTML element (a slow version of cat(1) basically). The callback methods may be overridden to modify the filtering for some HTML elements and you can override output() method which is called to print the HTML text. "HTML::Filter" is a subclass of "HTML::Parser". This means that the document should be given to the parser by calling the $p->parse() or $p->parse_file() methods. EXAMPLES
The first example is a filter that will remove all comments from an HTML file. This is achieved by simply overriding the comment method to do nothing. package CommentStripper; require HTML::Filter; @ISA=qw(HTML::Filter); sub comment { } # ignore comments The second example shows a filter that will remove any <TABLE>s found in the HTML file. We specialize the start() and end() methods to count table tags and then make output not happen when inside a table. package TableStripper; require HTML::Filter; @ISA=qw(HTML::Filter); sub start { my $self = shift; $self->{table_seen}++ if $_[0] eq "table"; $self->SUPER::start(@_); } sub end { my $self = shift; $self->SUPER::end(@_); $self->{table_seen}-- if $_[0] eq "table"; } sub output { my $self = shift; unless ($self->{table_seen}) { $self->SUPER::output(@_); } } If you want to collect the parsed text internally you might want to do something like this: package FilterIntoString; require HTML::Filter; @ISA=qw(HTML::Filter); sub output { push(@{$_[0]->{fhtml}}, $_[1]) } sub filtered_html { join("", @{$_[0]->{fhtml}}) } SEE ALSO
HTML::Parser COPYRIGHT
Copyright 1997-1999 Gisle Aas. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2008-04-04 HTML::Filter(3pm)
All times are GMT -4. The time now is 04:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy