Isolate text with sed or similar utility


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Isolate text with sed or similar utility
# 1  
Old 09-21-2015
Isolate text with sed or similar utility

All,

I'm getting a list like the following and I'd like to kill each PID in turn.

Code:
        pid (17797)
        pid (21748)
        pid (21754)
        pid (21704)
        pid (2199)
        pid (2159)
        pid (17809)
        pid (21769)
        pid (21778)
        pid (21715)
        pid (2211)
        pid (2171)

How can I isolate the PID in ksh with sed or other utility?
Thank you!

Last edited by Scrutinizer; 09-21-2015 at 01:14 PM.. Reason: code tags
# 2  
Old 09-21-2015
No idea yourself?
# 3  
Old 09-22-2015
Managed to extract numbers with sed using following command:

Code:
sed "s/[^0-9]//g"

---------- Post updated at 04:43 AM ---------- Previous update was at 04:42 AM ----------

What if I wanted to extract everything in between parentheses ( ) regardless of what's in there (letters, numbers, symbols, etc)?
This User Gave Thanks to ejianu For This Post:
# 4  
Old 09-22-2015
Hello ejianu,

Following may help you in same.
Code:
awk -F"[)(]" '{print $2}' Input_file
OR
sed 's/.*(//;s/).*//;'  Input_file

Output will be as follows.
Code:
17797
21748
21754
21704
2199
2159
17809
21769
21778
21715
2211
2171

EDIT: Adding one more solution with shell for same.
Code:
while read line
do
   line=${line##*(};
   echo ${line%%)*};
done < Input_file

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-22-2015 at 08:12 AM.. Reason: Added a sed solution now for same. Added a parameter expansion solution for same now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Why Parsing Can't be Done With sed ( or similar tools)

Regularly we have questions like: i have an XML (C, C++, ...) file with this or that property and i want to extract the content of this or that tag (function, ...). How do i do it in sed? Yes, in some (very limited) cases this is possible, but in general this can't be done. That is: you can do... (0 Replies)
Discussion started by: bakunin
0 Replies

2. Shell Programming and Scripting

Editing files with sed or something similar

{ "AFafa": "FAFA","AFafa": "FAFA" "baseball":"soccer","wrestling":"dancing" "rhinos":"crocodiles","roles":"foodchain" } I need to insert a new line before the closing brackets "}" so that the final output looks like this: { "AFafa": "FAFA","AFafa": "FAFA"... (6 Replies)
Discussion started by: SkySmart
6 Replies

3. Shell Programming and Scripting

Reducing text file using similar lines

Hello, I am a java programmer but want to try unix for a purpose where I need to reduce a file using its first field.. Here is the sample data: admin;2;0;; admission;8;0;; aman;1;0;; caroline;0;4;; cook;0;4;; cook;2;0;; far;0;3;; far;1;5;; I am explaining the dataset first. There... (5 Replies)
Discussion started by: shekhar2010us
5 Replies

4. Shell Programming and Scripting

Grep to isolate a text file line and Awk to select a word?

I am looking at using grep to locate the line in the text file and them use awk to select a word or words out of it. I know awk needs -v to allow a variable to be used, but also needs -F to allow the break up of the sentence and allow the location of separate variables. $line = grep "1:" File |... (8 Replies)
Discussion started by: Ironguru
8 Replies

5. Homework & Coursework Questions

script similar to rm utility

1. The problem statement, all variables and given/known data: saferm is a replacement for the rm utility. Rather than removing files, it move files in a sub directoy called".saferm" in the user's home directory. If "~/.saferm" doesn't exist, it is automatically created. The -l options lists the ... (3 Replies)
Discussion started by: Joey12
3 Replies

6. UNIX for Dummies Questions & Answers

sed to isolate file paths separated by a pattern

Hi, I've been searching for a quick way to do this with sed, but to no avail. I have a file containing a long series of (windows) file paths that are separated by the pattern '@'. I would like to extract each file path so that I can later assign a variable to each path. Here is the file:... (2 Replies)
Discussion started by: nixjennings
2 Replies

7. UNIX and Linux Applications

Free-text retrieval utility

Can anyone recommend an free-text retrieval utility? Open source or free preferred. Any views on say IQ-text? (0 Replies)
Discussion started by: MJDRM
0 Replies

8. UNIX for Dummies Questions & Answers

Appending text to a number of similar filenames

Hi, I was wondering if there was a way to append something to filenames based on a wildcard. For example, if I have the following files in a directory: blah1 blah2 blah3 blah4 blah5 I want to rename these all to: blah1.txt blah2.txt blah3.txt blah4.txt blah5.txt Is there a... (4 Replies)
Discussion started by: Djaunl
4 Replies

9. Shell Programming and Scripting

Sed utility

I am new to unix os. Can you explain in short about sed? with some examples. (1 Reply)
Discussion started by: Padmav
1 Replies

10. UNIX for Dummies Questions & Answers

Sed utility

Hi, Can you explain little bit with example regarding SED utility in UNIX? How iit is different then grep command? Thanks in advance. Malay (4 Replies)
Discussion started by: malaymaru
4 Replies
Login or Register to Ask a Question