Grep empty space and sort


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep empty space and sort
# 1  
Old 06-10-2011
Grep empty space and sort

Hi Expert,

Kindly request for your expertise in this matter.

I have below output:
Code:
12.125.124.173,xx1.common.com
12.125.124.174,xx2.common.com
12.125.124.175,xx3.common.com
12.125.124.176,
12.125.124.177,
12.125.124.178,
12.125.124.179,xx4.common.com
12.125.124.180,xx5.common.com
12.125.124.181,xx6.common.com
12.125.124.182,xx19.common.com
12.125.124.183,xx54.common.com
12.125.124.184,
12.125.124.185,
12.125.124.193,
12.125.124.194,
12.125.124.195,
12.125.124.196,xx33.common.com
12.125.124.197,xx89.common.com
12.125.124.198,xx88.common.com

and how do I script it to just appear with:
by omitting the xxx.common.com
Code:
12.125.124.176,
12.125.124.177,
12.125.124.178,
12.125.124.184,
12.125.124.185,
12.125.124.193,
12.125.124.194,
12.125.124.195,

thank you.

Last edited by regmaster; 06-13-2011 at 03:53 AM.. Reason: grep
# 2  
Old 06-10-2011
Code:
grep -v "common" yourinputfile

# 3  
Old 06-10-2011
As you mentioned about sort,

Code:
grep -v "common" file|sort

# 4  
Old 06-10-2011
thanks for reply.

but how do I just grep blank instead of "common"?
I would like to have this output
Code:
12.125.124.176,
12.125.124.177,
12.125.124.178,

instead of

Code:
12.125.124.173,xx1.common.com
12.125.124.174,xx2.common.com
12.125.124.175,xx3.common.com

Thank you.

Last edited by radoulov; 06-10-2011 at 06:50 AM.. Reason: Code tags, please!
# 5  
Old 06-10-2011
if the comma is always present at the end of the line you want, use grep ',$'
# 6  
Old 06-10-2011
what do you mean balnk, you mean the second field after IP is blank or whole line is blank ?
# 7  
Old 06-10-2011
sed -n '/common/!p' <file name>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert newline when grep result is empty

Given a csv file with 40 columns with name, address, hometown etc. I use a bash command in 1 line which: 1. gets the address column and pipes that to 2. grep the first digit and everything that follows Command: awk -F ";" '{print $19}' /Users/jb/Desktop/ReorderTempTotal.csv | grep -o "\d.*"... (7 Replies)
Discussion started by: JBVeenstra
7 Replies

2. Shell Programming and Scripting

Issue using empty variable in grep command

Hi, I'm writing a shell script and trying to grep a variable value, it works fine as long as there is a value in /tmp/list.out which is captured in $DSK but sometimes the file tends to be empty and that is where I'm having an issue while using grep which returns nothing. I know I can use something... (15 Replies)
Discussion started by: mbak
15 Replies

3. Shell Programming and Scripting

How to check if the file is empty or has blank space.?

Hi, I am using KSH. I am trying to check if the output file is empty or not. I tried with ] but what i see is my file is empty but still manages to have a size of 1 instead of 0. But my file doesnot have anything its empty. I am not sure how to check this. can any one help? (10 Replies)
Discussion started by: Sharma331
10 Replies

4. Shell Programming and Scripting

Sort a file content with space

Hello, I need help on. I have a File which stores the information as below. It is space separated file, I want to keep only unique record in file based on file name. Also if you notice sometime filename with space appear in last column like (abc_ xyz1_bc12_20140312_c.xlsx) 03/17/2014 ... (9 Replies)
Discussion started by: kumar30213
9 Replies

5. Shell Programming and Scripting

Replace space with empty

Hi All, My Input is: 111.121 23212121 121.231 12678878 My output should be 111.12123212121 121.23112678878 in each row i need to replace that perticular space with empty. 8th position in the file for all rows. Please help me in this case .. Thanks (7 Replies)
Discussion started by: raju4u
7 Replies

6. UNIX for Dummies Questions & Answers

sort and find duplicates for files with no white space

example data 5666700842511TAfmoham03151008075205999900000001000001000++ 5666700843130MAfmoham03151008142606056667008390315100005001 6666666663130MAfmoham03151008142606056667008390315100005001 I'd like to sort on position 10-14 where the characters are eq "130MA". Then based on positions... (0 Replies)
Discussion started by: mmarshall
0 Replies

7. Shell Programming and Scripting

Grep for empty file

I have a program that takes a file in which I use a sed to remove some data that is not needed. If all of the data is removed. I want to grep for that in the file and print that there is no data left in the file. When I use sed, I replace a word with nothing but it still seems to leave a return... (5 Replies)
Discussion started by: plawr
5 Replies

8. UNIX for Dummies Questions & Answers

Help required on printing the line if third field is not a empty space

Hi Experts, I want to print the lines whose third field in non-empty/blank space. i.e. INPUT FILE/B] dcdccghjrry0yd cont dcdccttrk820529 cont rdekedfsSCr dcdccttrdky2d0y cont rdekedfsSC2 ... (3 Replies)
Discussion started by: krao
3 Replies

9. Shell Programming and Scripting

empty space in java command through unix

I need to pass an empty space in the command ="java ......... " as one of the arguments where java calls some java command.... (It accepts it in windows as " ") Thanks in advance SD (2 Replies)
Discussion started by: shweta_d
2 Replies

10. UNIX for Dummies Questions & Answers

How will you list only the empty lines in a file (using grep)

How will you list only the empty lines in a file (using grep) (1 Reply)
Discussion started by: JosephGerard
1 Replies
Login or Register to Ask a Question