awk delete/remove rest of line on multiple search pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk delete/remove rest of line on multiple search pattern
# 1  
Old 01-24-2012
awk delete/remove rest of line on multiple search pattern

Need to remove rest of line after the equals sign on search pattern from the searchfile. Can anybody help. Couldn't find any similar example in the forum:

infile:
HTML Code:
64_1535:  Delm.  = 86 var, aaga
64_1535:  Fran.  = 57 ex. ccc 
64_1639:  Feb.  = 26 (link). def 
64_1817:  mar.  = 3/4. drz 
64_1890:  Sc.  = 4420.  
64_1901:  No.  = 254. kjkj 
64_1902:  No.  = 273
64_1902:  Fr.  = 793. kle 
64_1903:  Ke.  = 2. sesg
searchfile:
HTML Code:
aaga
ccc 
def 
drz 
kjkj 
kle 
sesg
desired output (with or without the punctuation at the end):
HTML Code:
64_1535:  Delm.  = 86 var
64_1535:  Fran.  = 57 ex
64_1639:  Feb.  = 26 (link)
64_1817:  mar.  = 3/4
64_1890:  Sc.  = 4420  
64_1901:  No.  = 254 
64_1902:  No.  = 273
64_1902:  Fr.  = 793 
64_1903:  Ke.  = 2
# 2  
Old 01-24-2012
Sorry but example isn't detailed enough can you supply desired output from this input:

Code:
64_1535:  No equals here aaga
..........................
64_1535:  Delm.  = 86 var, aaga, ccc
64_1535:  Fran.  = 57 ex.,, ccc
64_1639:  ccc
64_1817:  mar.  = 3/4.... 
64_1890:  Sc.  = 4420  mar. = 3/4 aag
64_1891:  Dec.  = 420  not_in_search  ccc
64_1901:  No.  = 254 kjkj


Last edited by Chubler_XL; 01-24-2012 at 07:47 PM..
# 3  
Old 01-24-2012
Code:
awk '{gsub(/[,.].*/, "",$2)}1' FS="=" OFS="=" infile

This User Gave Thanks to rdcwayx For This Post:
# 4  
Old 01-24-2012
See sdf, you will get solutions like the above if you don't supply enough info on what you want.
# 5  
Old 01-24-2012
Quote:
Originally Posted by Chubler_XL
See sdf, you will get solutions like the above if you don't supply enough info on what you want.
You are too serious.
# 6  
Old 01-24-2012
Sorry, just caught me on a bad day I suppose.

I must admit I was very tempted to supply the following myself:
Code:
sed 's/[.,][^=.,]*$//' infile

This User Gave Thanks to Chubler_XL For This Post:
# 7  
Old 01-25-2012
Quote:
Originally Posted by sdf
Need to remove rest of line after the equals sign on search pattern from the searchfile. ... [/HTML]searchfile:
HTML Code:
aaga
ccc 
def 
drz 
kjkj 
kle 
sesg
Thanks for the suggestion. I was more looking for someting like this:

Code:
awk 'BEGIN{FS=OFS="="} NR==FNR {arr[$0]; next}{gsub(/[arr].*/, "",$2)}1' searchfile infile

Can't get gsub to work with an array as a search pattern.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete multiple occurrences of the same pattern on a line but the first

The lines that I am trying to format look like Device ID: j01-01, IP address: 10.10.10.36, IP address: 10.10.10.35, IP address: 10.10.102.201, Platform: 8040, Capabilities: Host , Interface: GigabitEthernet9/45, Port ID (outgoing port): e0k,Here is what I have so far but it... (4 Replies)
Discussion started by: dis0wned
4 Replies

2. UNIX for Dummies Questions & Answers

How to delete blank line/s before and after a search pattern?

Hi, Test file x.txt below. This file is generated by a program that I unfortunately do not have control on how it gets presented/generated. create PACKAGE "XXX_INTERFACE_DEFECT_RPT_TEST" is TYPE refCursor IS REF CURSOR; Function queryRecords ( p_status varchar2, ... ... ... )... (4 Replies)
Discussion started by: newbie_01
4 Replies

3. Shell Programming and Scripting

Multiple pattern find and delete line

I have a file # cat /tmp/user_find.txt /home/user/bad_link1 /home/user/www /home/user/mail /home/user/access_logs /home/user/bad_link2 I need to delete lines where there are patterns /home/user/www, /home/user/mail and /home/user/access_logs. I used below method, but its throwing error... (8 Replies)
Discussion started by: anil510
8 Replies

4. Shell Programming and Scripting

awk to search for pattern and remove line

I am an awk beginner and need help figuring out how to search for a number in the first column and if it (or anything greater) exists, remove those lines. AM11400012012 2.26 2.12 1.98 2.52 3.53 3.01 3.62 5.00 3.65 7.95 0.79 3.88 0.00 AM11400012013 3.39 2.29 ... (1 Reply)
Discussion started by: ncwxpanther
1 Replies

5. Shell Programming and Scripting

Search a pattern in a line and remove another pattern

Hi, I want to search a pattern in a text file and remove another pattern in that file. my text file look like this 0.000000 1.970000 F 303 - 1.970000 2.080000 VH VH + 2.080000 2.250000 VH VH + 2.250000 2.330000 VH L - 2.330000 2.360000 F H + 2.360000 2.410000 L VL - 2.410000 ... (6 Replies)
Discussion started by: sreejithalokkan
6 Replies

6. Shell Programming and Scripting

awk with multiple pattern search

Want to fetch a column with multiple pattern using awk. How to achieve the same. Tried cat test address : 10.63.20.92/24 address : 10.64.22.93/24 address : 10.53.40.91/24 cat test | awk '{print $3}' |awk -F "/" '{print $1}' 10.63.20.92 10.64.22.93 10.53.40.91 Is there any... (2 Replies)
Discussion started by: Manasa Pradeep
2 Replies

7. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

8. Homework & Coursework Questions

sed Multiple Pattern search and delete the line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have file which has got the following content sam 123 LD 41 sam 234 kp sam LD 41 kam pu sam LD 61 Now... (1 Reply)
Discussion started by: muchyog
1 Replies

9. UNIX for Advanced & Expert Users

Delete rest of the line

Hi, can anyone please answer my question in deleting the rest of the line. I have an example below of a file contaning: Serial3/1.5 43.70.195.13 YES NVRAM down down Serial3/3 225.94.155.69 YES NVRAM up down Serial3/6 ... (3 Replies)
Discussion started by: Aejaz
3 Replies

10. Shell Programming and Scripting

Multile Pattern Search in a same line and delete

HI Gurus, I need to delete a line from a syslog file, if it matches three conditions. Say for ex., if the device name is device.name.com and if it contains the syslog message PAGP-5-PORTFROMSTP in between the time period 00:00:00 to 04:00:00, then the particular line has to be deleted from... (2 Replies)
Discussion started by: sasree76
2 Replies
Login or Register to Ask a Question