How to print only word with "_" or @ of a file?

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print only word with "_" or @ of a file?
# 1  
Old 07-06-2011
How to print only word with "_" or @ of a file?

Hello all,

I have a text file but I need to have only words with string "_" or "@"


text LD_ titi
blbla blabla name@domain lalala
titi name2@domain2 toto


LD_ titi

How can I do to do with linux? thanks in advance!
# 2  
Old 07-06-2011
"titi" is expected ???

xargs -n1 <yourfile | egrep -e '_|@'

---------- Post updated at 05:48 PM ---------- Previous update was at 05:44 PM ----------

Last edited by ctsgnb; 07-06-2011 at 01:06 PM..
# 3  
Old 07-06-2011
grep -Eo '([^ ]*@[^ ]*)|([^ ]*_[^ ]*)' file

# 4  
Old 07-06-2011
Try this,
for i in `cat r`; do echo $i | egrep "@|_"; done
# 5  
Old 07-06-2011
Thank you Ctsgnb but xargs don't work to the end of the file, I got this error:
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

And the sed command don't show the whole pattern Smilie
sed 's/[^ @_][^ @_]*//g;s/  */ /g;s/^ //;s/ $//'

---------- Post updated at 11:03 AM ---------- Previous update was at 10:56 AM ----------

Originally Posted by Rksiva
Hi Rkisiva,
I can't run this command, can you explain how to use it please?
# 6  
Old 07-06-2011
Try execute like below,

for i in `cat <Input Filename>`
echo $i | egrep "@|_"

This User Gave Thanks to Rksiva For This Post:
# 7  
Old 07-06-2011
for me it works :
You right, the sed statement is erroneous i fixed my post.

# xargs -n1 <tst | egrep -e '_|@'

This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Why awk print is strange when I set FS = " " instead of FS = "\t"?

Look at the following data file( which has four fields separated by tab. Four fields are country name, land area, population, continent where it belongs. As for country name or continent name which has two words, two words are separated by space. (Data are not accurately... (1 Reply)
Discussion started by: chihuyu
1 Replies

3. Shell Programming and Scripting

How do i replace a word ending with "key" using awk excpet for one word?

echo {mbr_key,grp_key,dep_key,abc,xyz,aaa,ccc} | awk 'gsub(/^|abc,|$/,"") {print}' Required output {grp_key,xyz,aaa,ccc} (5 Replies)
Discussion started by: 100bees
5 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

awk based script to print the "mode(statistics term)" for each column in a data file

Hi All, Thanks all for the continued support so far. Today, I need to find the most occurring string/number(also called mode in statistics terminology) for each column in a data file (.csv type). For one column of data(1.txt) like below Sample 1 2 2 3 4 1 1 1 2 I can find the mode... (6 Replies)
Discussion started by: ks_reddy
6 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Solaris

How to check "faulty" or "stalled" print queues - SAP systems?

Hi all, First off, sorry for a long post but I think I have no other option if I need to explain properly what I need help for. I need some advise on how best to check for "faulty" or "stalled/jammed' print queues. At the moment, I have three (3) application servers which also acts as print... (0 Replies)
Discussion started by: newbie_01
0 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Shell Programming and Scripting

Perl - How to print a "carriage return" to an output file?

Let's say I want to write a program that run these 4 UNIX commands and redirect output to a file. #!/usr/local/bin/perl use strict; `cd \$HOME > output.txt`; `cut -f1 inputfile.txt >> output.txt`; `hostname >> output.txt`; `ifconfig >> output.txt`; I want to print a "carriage return"... (5 Replies)
Discussion started by: teiji
5 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep ""|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep ""|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question