-2

Okay.I will be very specific with what I want.I need to write a script a which processes a numerous files and it has following type of xmls in those files:

<NotificationList>   
    <Name>Postpaid</Name>
    <Amount>5.0</Amount>
    <IsRecurring>0</IsRecurring>
    <ThresholdLimit>5.0</ThresholdLimit>
    <ObjectType>1</ObjectType>
    <subscription>1010984</subscription>
    <NotificationTime>2018-05-> 
    31T00:18:46.000000+01:00</NotificationTime>

I need to get the name, subscription, NotificationTime for each of the xml in column wise. I am able to print these values in rows one below the other by doing grep -A 8 "" * | grep 'name\|subscription\|NotificationTime'

Hope am clear this time.

  • 3
    Can you demonstrate *any* effort at solving this yourself? – Scott Hunter Jun 08 '18 at 12:49
  • you can use vi in unix - it must be there and it has macros - all you need (good tutorials on vi here: http://derekwyatt.org/vim/tutorials/) – Drako Jun 08 '18 at 12:50
  • Possible duplicate of [How to show only next line after the matched one?](https://stackoverflow.com/questions/7451423/how-to-show-only-next-line-after-the-matched-one) – Tom Fenech Jun 08 '18 at 14:11

2 Answers2

0

This can be done by

grep -rnw '/path/to/file/file.format' -e "Hello this is the"

If you are inserting the notification from other command in text file you can add comment to make it easy to search for or syntax of the notification like shown above.

#You can add comment for notification which will make it easy to find all notifications by tag.

#Hello notification
Hello instance 1
#Navigation notification
Turn right instance 1
#Hello notification
Hello instance 2

EDIT: I think what Tom Fenech linked is what you are looking for. If indeed it is, it is a duplicate question.

0

This can be achieved by

grep -e name -e subscription -e NotificationTime filename.txt | cut -d ">" -f2 | cut -d "<" -f1 | paste -d , - - -

Using paste command you can print multiple searched patterns into a line with any specific delimeters.

Description "paste -- : Combining N consecutive lines: The paste command can also be used to merge N consecutive lines from a file into a single line. Here N can be specified by specifying number hyphens(-) after paste."