LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-19-2016, 03:03 AM   #16
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,166

Rep: Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751Reputation: 751

I came up with a pure bash solution because.... I wanted to...

Code:
#!/bin/bash

while IFS=":" read -r item value ; do

  if [[ ${item} == "Application Name" ]] ; then
    myapp=${value}
  fi

  if [[ ${item} == "Status" ]] && [ ${value} == "Running" ] ; then
      echo "${myapp} is running"
      myapp=""
  fi

done < test.dat
This also takes in to consideration additions or subtractions from the file, as long as the Application Name: line is before the Status: line it should work, even if other lines are added or subtracted.

In reality I'd have used the awk suggestion, but just wanted to see if I could do it purely in bash.

edit: Just noticed this is pretty similar to grail's solution (post #14)

Last edited by TenTenths; 08-19-2016 at 03:31 AM.
 
Old Yesterday, 03:43 AM   #17
linuxuser06
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I would use awk instead of grep:
Code:
awk ' /^Application Name:/ { n=$NF }
      /^Status: Running/ { print n } ' filename
Hey

This was working fine for most of the cases. But recently we got a test case like below and it did not work accurately.

Sample data in file
<<Application Name: abc def_ghi/def_ghi/def_ghi
Service Name: abc_def_ghi.par
Deployment Status: Success
Service Instance Name: abc_def_ghi
Machine Name: abc00a0194
Status: Running>>

On running below code it is giving output as "def_ghi/def_ghi/def_ghi" rather than "abc def_ghi/def_ghi/def_ghi"
Code:
 
awk ' /Application Name:/ { n=$NF }
      /Status: Running/ { print n } ' output.txt
Can you please suggest some modification in this awk command so that it displays the complete application name including the space?

thanks in advance.
 
Old Yesterday, 03:46 AM   #18
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,122

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
probably awk -F: '...... ' output.txt will help
 
1 members found this post helpful.
Old Yesterday, 03:49 AM   #19
avijadhav
LQ Newbie
 
Registered: May 2012
Posts: 14
Blog Entries: 2

Rep: Reputation: Disabled
hey friends

how to update 6.3 to 6.11 Redhat server online and offline please give me step

Last edited by avijadhav; Yesterday at 03:56 AM.
 
Old Yesterday, 03:59 AM   #20
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,122

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
please do not hide threads, open a new one if you need help (from the other side please ask Redhat)
 
Old Yesterday, 04:48 AM   #21
linuxuser06
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
probably awk -F: '...... ' output.txt will help
that worked!! cool thanks!!
 
Old Yesterday, 01:50 PM   #22
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,102
Blog Entries: 10

Rep: Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524
Quote:
Originally Posted by avijadhav View Post
hey friends

how to update 6.3 to 6.11 Redhat server online and offline please give me step
avijadhay,

Do not crosspost or hijack other threads, and keep this same question within the original thread you created on this subject. Meanwhile fix your question in that thread to be able to obtain better assistance on this matter.

Persisting with this type of behavior will not be helpful to you or the LQ forum.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read .log format file and get special character from some lines by shell scripting samasara Linux - Newbie 32 12-21-2013 03:17 AM
shell scripting for extracting input from different directorires kswapnadevi Linux - Newbie 7 11-09-2010 07:10 AM
deleting particular lines using shell scripting ibabhelix Linux - Newbie 9 11-02-2009 01:26 AM
extracting particular lines from a text file skuz_ball Programming 18 10-28-2008 01:31 PM
Inserting lines into a file through shell scripting false-hopes Linux - General 1 10-22-2005 12:39 PM


All times are GMT -5. The time now is 12:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration