LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 02:03 AM   #16
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,413

Rep: Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540Reputation: 1540

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 02:31 AM.
 
Old 12-06-2016, 02: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 12-06-2016, 02:46 AM   #18
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,237

Rep: Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836
probably awk -F: '...... ' output.txt will help
 
1 members found this post helpful.
Old 12-06-2016, 02: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; 12-06-2016 at 02:56 AM.
 
Old 12-06-2016, 02:59 AM   #20
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,237

Rep: Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836
please do not hide threads, open a new one if you need help (from the other side please ask Redhat)
 
Old 12-06-2016, 03: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 12-06-2016, 12:50 PM   #22
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
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 02:17 AM
shell scripting for extracting input from different directorires kswapnadevi Linux - Newbie 7 11-09-2010 06:10 AM
deleting particular lines using shell scripting ibabhelix Linux - Newbie 9 11-02-2009 12:26 AM
extracting particular lines from a text file skuz_ball Programming 18 10-28-2008 12:31 PM
Inserting lines into a file through shell scripting false-hopes Linux - General 1 10-22-2005 11:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:18 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
Open Source Consulting | Domain Registration