Matching some string in a line and removing that


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matching some string in a line and removing that
# 1  
Old 07-16-2013
Matching some string in a line and removing that

I have one output file.

Code:
Node: hstg1so                                  Date: 2013/07/16 17:51:24  GMT
Totals:                  10608  6871     0  2208   1529     0     0               64%    0% (    0 )


Node: hstg2so                                  Date: 2013/07/16 17:51:25  GMT
Totals:                   8136  5448     0  1736    952     0     0               66%    0% (    0 )


Node: hstg3so                                  Date: 2013/07/16 17:51:28  GMT
HSTNTX01QADAVM1I        288   287        0     0      0     0     0 INSERVICE     99%    0% (    1 )
Totals:                   9360  5168     0  2552   1639     0     0               55%    0% (    1 )


Node: hstg4so                                  Date: 2013/07/16 17:51:30  GMT
Totals:                   8544  4454     0  2110   1980     0     0               52%    0% (    0 )


Node: hstg5so                                  Date: 2013/07/16 17:51:32  GMT
SNANTX78GT0AIM2I        840   737        0   102      0     0     0 INSERVICE     87%    0% (    1 )
Totals:                  10896  6047     0  3152   1696     0     0               55%    0% (    1 )


Node: hstg6so                                  Date: 2013/07/16 17:51:35  GMT
Totals:                  10080  6226     0  1018   2836     0     0               61%    0% (    0 )

I want to remove Date: 2013/07/16 17:51:35 GMT from file.

That from

Code:
Node: hstg6so                                  Date: 2013/07/16 17:51:35  GMT

I only want Node: hstg6so.

I tried some sed function but it's not working.


sed -e 's/Date*GMT//g'


But it's not working.
Please suggest a solution.


Moderator's Comments:
Mod Comment Use code tags also for logs and data. Read the guide you got per PM if you want to avoid further infractions etc.

Last edited by zaxxon; 07-16-2013 at 03:14 PM..
# 2  
Old 07-16-2013
try:
Code:
awk ' $0 !~ dt ' RS="" ORS="\n\n" dt="2013/07/16 17:51:35" infile.txt

# 3  
Old 07-16-2013
Hi rdrtx1,

Thanks for reply,

Code is giving syntax error.
One more Point I want to remove this " Date: 2013/07/16 17:51:35 GMT"

In which "Date: GMT" space part is any time that is not fixed.
# 4  
Old 07-16-2013
Try a small adaption to rdrtx1's proposal:
Code:
awk '{sub("Date: " dt "  GMT","")}1 ' RS="" ORS="\n\n" dt="2013/07/16 17:51:35" file

And, post the error msgs should some come up.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to uppercase matching line when string found?

Hello, Could you please help me how to search the string in a file, and when found; change the existing line to uppercase in command line? I tried: ?whichcommand? -A "EXT" fileA | awk '{print tolower($0)}' | tee fileB tr command simply converts entire file to uppercase but this is not what... (4 Replies)
Discussion started by: baris35
4 Replies

2. Shell Programming and Scripting

Removing spaces from line matching a pattern

Hi, I want to remove the spaces from all the lines matching a particular pattern from my file. For instance in file abc.txt I have following data. Header,This is the header 111,this is 1st record 222, this is 2nd record 333, this is 3rd record Footer,3 records found Footer,111222333 ... (5 Replies)
Discussion started by: decci_7
5 Replies

3. Shell Programming and Scripting

Replace line in file with line in another file based on matching string

HI Can any one guide me how to achieve this task. I have 2 files env.txt #Configuration.Properties values identity_server_url = http://identity.test-hit.com:9783/identity/service/user/register randon_password_length = 6 attachment_file_path = /pass/temp/attachments/... (1 Reply)
Discussion started by: nikilbr86
1 Replies

4. Shell Programming and Scripting

Replace and add line in file with line in another file based on matching string

Hi, I want to achieve something similar to what described in another post: The difference is I want to add the line if the pattern is not found. File 1: A123, valueA, valueB B234, valueA, valueB C345, valueA, valueB D456, valueA, valueB E567, valueA, valueB F678, valueA, valueB ... (11 Replies)
Discussion started by: jyu3
11 Replies

5. Shell Programming and Scripting

Deleting a matching string(line) which is also in other lines

Hi, i need help with my shell script I have a file input.txt containing the following contents /. /usr /usr/share /usr/share/doc /usr/share/doc/wine /usr/share/doc/wine/copyright /usr/share/doc/wine/changelog.Debian.gz I need output as /usr/share/doc/wine /usr/share/doc/wine/copyright... (3 Replies)
Discussion started by: Amit0991
3 Replies

6. Shell Programming and Scripting

Removing command line arguments from string list

I am passing a list of strings $list and want to remove all entries with --shift=number, --sort=number/number/..., --group=number/number/... Also are removed whether upper or lower case letters are used For example the following will all be deleted from the list --shift=12 --shift=2324... (7 Replies)
Discussion started by: kristinu
7 Replies

7. Shell Programming and Scripting

Removing string between two particular strings in a line

Hi, I have a file with following format: 1|What is you name (full name)?|Character 2|How far is your school ?|Numeric Now I need to remove everything inside brackets () or . There can be more than one pair of brackets. The output file should look like: 1|What is you name?|Character... (8 Replies)
Discussion started by: ppatra
8 Replies

8. Shell Programming and Scripting

Removing a line IF the next line contains string

So, I've been working on a project which takes layer 7 metadata from pcap dumps and archives it. However, there is a lot of dataless information that I don't want in my output. I know of ways to produce the output I want from the input file below, but I want a method of doing this, regardless of... (2 Replies)
Discussion started by: eh3civic
2 Replies

9. Shell Programming and Scripting

Extracting a string matching a pattern from a line

Hi All, I am pretty new to pattern matching and extraction using shell scripting. Could anyone please help me in extracting the word matching a pattern from a line in bash. Input Sample (can vary between any of the 3 samples below): 1) Adaptec SCSI RAID 5445 2) Adaptec SCSI 5445S RAID 3)... (8 Replies)
Discussion started by: jharish
8 Replies

10. Shell Programming and Scripting

find out line number of matching string using grep

Hi all, I want to display line number for matching string in a file. can anyone please help me. I used grep -n "ABC" file so it displays 6 ABC. But i only want to have line number,i don't want that it should prefix matching context with line number. Actually my original... (10 Replies)
Discussion started by: sarbjit
10 Replies
Login or Register to Ask a Question