Need help with how to search a file for a variable string and delete that line


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Need help with how to search a file for a variable string and delete that line
# 8  
Old 02-26-2019
I don't have access to a Solaris system so can't test anything, but looking at (and shamelessly stealing from) Don Cragun's post, the following one liner might work without using a temp file:
Code:
sed 's/:.*$//' list.err | /usr/xpg4/bin/grep -vf- list.all

# 9  
Old 02-26-2019
Quote:
Originally Posted by RudiC
I don't have access to a Solaris system so can't test anything, but looking at (and shamelessly stealing from) Don Cragun's post, the following one liner might work without using a temp file:
Code:
sed 's/:.*$//' list.err | /usr/xpg4/bin/grep -vf- list.all

Hi RudiC,
That is certainly worth a try.

I no longer have access to a Solaris system either, but I did think of that and tried it on macOS Mojave (version 10.14.3) which uses a BSD derived grep. It doesn't work there.

Furthermore, the standards allow (but do not require) file operands specified as - to be treated by grep as a synonym for reading from standard input. The standards do not say anything about allowing the -f pattern_file option-argument to be treated the same way. Therefore, I doubt that a Solaris /usr/xpg4/bin/grep will accept a - as anything other than the actual name of a real file for that option-argument even if they do treat - that way when used as a file operand.

Hi newbie_01,
Would you like to try that for us on your Solaris system and let us know what happens?
# 10  
Old 02-26-2019
Quote:
Originally Posted by newbie_01
I think I should start adding that in all of the scripts especially for SIGKILL=9 when we have to do a kill -9.
Expanding on what Don Cragun has already explained: The difference between "9" and all other signals a process can get is that "9" (like in kill -9) is not handled by the process itself. Itis handled by the system (that is: a part of the kernel).

When you issue the command kill -n <PID> (for n being some number - see kill -l for a list of all legal values) this generates a "signal" which is then passed to the process and handled by it. In principle a process can react however it wants (or even not at all) to a specific signal but there are conventions and therefore expected reactions of a process to a certain signal. i.e. kill -1 usually causes a process to re-read its configuration file(s) and then resume operation using this new configuration.

The ultimate signal you can send to a process is "15" which means "terminate immediately". A well-behaved process will then terminate, no matter what it is doing. Still, "terminating" here means not just "exit" but to perform every cleanup possible: it there are temporary files open, then close them and remove them, if there are network connections open close them and free up the sockets, etc..

This is the main difference between signal 15 and 9: with 9 the process will not be notified but immediately (and in the most brutal way possible) removed by the OS. It will simply have no time to clean up, in fact it isn't even aware of it being killed.

Therefore, when you want to stop a process, always try kill -15 at least once (better: two to three times) and only if the process is proven not to be able to terminate itsself any more try a kill -9 - but ONLY then. Your system will remain much more stable because processes will have the chance to clean up (and well-behaved UNIX processes do that!).

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 11  
Old 02-26-2019
Thank you :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Search for a string,delete the line and replace with new string in a file

Hi Everyone, I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file. I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies

2. Shell Programming and Scripting

Search string within a file and list common words from the line having the search string

Hi, Need your help for this scripting issue I have. I am not really good at this, so seeking your help. I have a file looking similar to this: Hello, i am human and name=ABCD. How are you? Hello, i am human and name=PQRS. I am good. Hello, i am human and name=ABCD. Good bye. Hello, i... (12 Replies)
Discussion started by: royzlife
12 Replies

3. Shell Programming and Scripting

Search a string in a text file and add another string at the end of line

Dear All I am having a text file which is having more than 200 lines. EX: 001010122 12000 BIB 12000 11200 1200003 001010122 2000 AND 12000 11200 1200003 001010122 12000 KVB 12000 11200 1200003 In the above file i want to search for string KVB... (5 Replies)
Discussion started by: suryanarayana
5 Replies

4. Shell Programming and Scripting

Sed find exact string and delete line with variable

All, I am trying to read in a variable and search a file then delete based on that string, but i want to match exact word. This works but it matches all, i don't want to match anthing that contains the string, just the exact string. sed -i "/$feedname/d" file I tried sed... (1 Reply)
Discussion started by: markdjones82
1 Replies

5. UNIX for Dummies Questions & Answers

search for a string and delete it from the file

Hi , I am breaking my head from past one day ...to delete lines from a file which match to the string pattern.:wall: I am storing the search string in a variable and search if the file exists in the folder,if not delete that entry from the file. I am having problem to delete that line from... (2 Replies)
Discussion started by: rashmisb
2 Replies

6. Shell Programming and Scripting

Grep a string from input file and delete next three lines including the line contains string in xml

Hi, 1_strings file contains $ cat 1_strings /home/$USER/Src /home/Valid /home/Review$ cat myxml <projected value="some string" path="/home/$USER/Src"> <input 1/> <estimate value/> <somestring/> </projected> <few more lines > <projected value="some string" path="/home/$USER/check">... (4 Replies)
Discussion started by: greet_sed
4 Replies

7. Shell Programming and Scripting

Search for a line, delete a string in it

let me start out by saying i have ZERO exp with any kind of scripting, so sorry if this is really basic stuff..... For example, I need to have a script that will search a file and find this line in the file: *.cat;dog;kennel;house;barn;horse;hay;coat hat and remove the "coat" from the... (12 Replies)
Discussion started by: skunky
12 Replies

8. Shell Programming and Scripting

search a string in a line and save it in a variable

Hi I want to read a file line by line and search for a particular string in each line(say for example string containing @ )and save that string into a variable. Can someone suggest me the way to implement it.I am using K- shell Thanks Ishita (5 Replies)
Discussion started by: Ishita
5 Replies

9. Shell Programming and Scripting

search string and delete the line

Hi All, I have a file from Mainframe which has one of the lines with so many words... i tried to fold, format to 80 chararcter.. stil did not work. So i have decided to search for a string in that line Ex.FLIGHT PLAN and once if it is found i want to delete the entire line. Please help... (2 Replies)
Discussion started by: digitalrg
2 Replies

10. Shell Programming and Scripting

Search for string in a file and extract another string to a variable

Hi, guys. I have one question: I need to search for a string in a file, and then extract another string from the file and assign it to a variable. For example: the contents of the file (group) is below: ... ftp:x:23: mail:x:34 ... testing:x:2001 sales:x:2002 development:x:2003 ...... (6 Replies)
Discussion started by: daikeyang
6 Replies
Login or Register to Ask a Question