Shell script to remove some content in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to remove some content in a file
# 1  
Old 08-10-2011
Shell script to remove some content in a file

How can I remove all data that contain domain e.g zzgh@something.com, sdd@something.com.my and gg@something.my in one file? so that i only have data without the domain in the file.

Here is the file structure "test.out"
Code:
more test.out
   1 zzztop@b.com
   1 zzzulll
   1 zzzullll@s.com.my
   1 zzzuri@b.com
   1 zzzurita@b.my
   1 zzzx
   1 zzzxxx92
   1 zzzxxx@b.com
   1 zzzxy85@s.com
   1 zzzz
   1 zzzz1861@b.com
   1 zzzz23@b.com.my
   1 zzzz5879
   1 zzzz888
   1 zzzz@s.my
   1 zzzzdaud
   1 zzzzin
   1 zzzzz
   1 zzzzz@b.com
   1 zzzzz@s.com
   1 zzzzznndr@b.com
   1 zzzzzz@b.com

output should be like this,
Code:
zzzulll
zzzx
zzzxxx92
zzzz
zzzz5879
zzzz888
zzzzdaud
zzzzin
zzzzz

# 2  
Old 08-10-2011
One way would be..
Code:
awk '!/@/ {print $2}' inputfile > outfile

This User Gave Thanks to michaelrozar17 For This Post:
# 3  
Old 08-10-2011
Dude michaelrozar17,

thank you very much. it works 100%, may i know where can i get some note or guide to read on how to start creating shell script like you do?
# 4  
Old 08-10-2011
One way you can start is learning regular expressions.

Here is another way of solving your problem using 'sed':
Code:
sed '/@/d' Input_File

This User Gave Thanks to Shell_Life For This Post:
# 5  
Old 08-11-2011
thx both works just fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to sort a content of a text file using a shell script?

I am new to shell scripting. I am interested how to know how to sort a content of a file using shell scripting. I've attached the 'Input file' and the 'expected output' to this thread. Details provided in the expected output file will provide details on how the sort needs to be done. ... (16 Replies)
Discussion started by: nkarthik_mnnit
16 Replies

2. Shell Programming and Scripting

How to remove exisiting file content from a file and have to append new file content?

hi all, i had the below script x=`cat input.txt |wc -1` awk 'NR>1 && NR<'$x' ' input.txt > output.txt by using above script i am able to remove the head and tail part from the input file and able to append the output to the output.txt but if i run it for second time the output is... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Shell Programming and Scripting

Script to remove same content from other file

Hi/ Hello all Guru here, I am trying to create script to remove same content from other file, already tested few idea and found that in unix it is limited to sort and uniq. There is many script for removing duplicate content however to delete all same content is non. Need your help and guide .... (7 Replies)
Discussion started by: Mr_47
7 Replies

4. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

5. Shell Programming and Scripting

Shell script to monitor new file in a directory and mail the file content

Hi I am looking for a help in designing a bash script on linux which can do below:- 1) Look in a specific directory for any new files 2) Mail the content of the new file Appreciate any help Regards Neha (5 Replies)
Discussion started by: neha0785
5 Replies

6. Shell Programming and Scripting

How can I write the specific content in the file through shell script

Hello, I need to do one thing that my script creates the file touch release.SPLASH_12_03_00_RC01.txt Now I want to update that file with some content e.g splashbuild::SPLASH_12_17_00_RC02.zip Thanks (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

7. Shell Programming and Scripting

Problem getting the content of a file in a shell script variable

Hi, I have a text file that has a long multi-line db2 CTE query. Now I want to store all the contents of this file (i.e. the entire query) in a shell script variable. I am trying to achieve it by this: query = `cat /Folder/SomeFile.txt` But when I echo the contents of this file by saying echo... (4 Replies)
Discussion started by: DushyantG
4 Replies

8. Shell Programming and Scripting

Delete content of file 1 in file 2 with shell script

OK, best is I explain what the operating enviroment is. Linux, but Motomagx. It is a Linux operated mobile phone, Motorola V8. I am writting a shell script, but got stuck. I have to delete the complete content of file 1 in file 2. I have attached the 2 files. You can see that the content of... (2 Replies)
Discussion started by: rasputin007
2 Replies

9. Shell Programming and Scripting

shell script to search content of file with timestamps in the directory

hello, i want to make a script to search the file contents in my home directory by a given date and output me the line that has the date... (10 Replies)
Discussion started by: psychobeauty
10 Replies

10. Shell Programming and Scripting

shell script to edit the content of a file

Hi I need some help using shell script to edit a file. My original file has the following format: /txt/email/myemail.txt /txt/email/myemail2.txt /pdf/email/myemail.pdf /pdf/email/myemail2.pdf /doc/email/myemail.doc /doc/email/myemail2.doc I need to read each line. If the path is... (3 Replies)
Discussion started by: tiger99
3 Replies
Login or Register to Ask a Question