extract/cut desired output from a line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract/cut desired output from a line
# 1  
Old 03-15-2012
extract/cut desired output from a line

Hi all ,

my script is sending output to a file , output is in below format :-
Quote:
/tmp/check_sync/TBS_CELLTADM_LIST_celltadm@avm-siapp01_list
i want to cut , celltadm@avm-siapp01 from this output line . Starting and ending words can vary , like it can be any name as below -
Quote:
/tmp/check_sync/ABCD_LIST_celltadm@avm-siapp01_final_list
so there will be only one "@" and i want to cut word just before and after this.(_ is also there)
# 2  
Old 03-15-2012
If I understand correctly and you want foo@bar extracted from stuff_foo@bar_more_stuff, then I think this will work as long as foo@bar does NOT contain an underbar (_):

Code:
sed -r 's/(.*)(_[^_]+@[^_]*.)(.*)/\2/; s/_//g' input-file >output-file



If you are on a system that has a BSD oriented sed, then use -E instead of -r.
# 3  
Old 03-16-2012
yes, you are correct ,format is right.
sed with -r and -E not working .
also, what about if it has same format as i mentioned with underscore ?
# 4  
Old 03-16-2012
Quote:
Originally Posted by deepakiniimt
sed with -r and -E not working .
What operating system?


So there might be foo_foo@bar and/or foo@bar_bar that you want to snarf? That's tougher -- how do you determine when list_foo_foo@bar shouldn't be treated just as list_foo@bar?
# 5  
Old 03-16-2012
operating system is:-
HP-UX bat-siapp03 B.11.31 U ia64

well, we can say foo and bar are unique , they will not repeat in whole line.
so
Quote:
list_foo_foo@bar and list_foo@bar_bar
will not appear .
# 6  
Old 03-16-2012
foo_foo isn't as important as the underbar (_) between them. If what you want to capture before the @ has an underbar, as does the text that you want to ignore before it, then something else is needed to key off of in order to determine that word1_word2_word3@word4_word5 should be captured as word2_word3@word4 instead of word3@word4.
# 7  
Old 03-16-2012
can we extract desired output word3@word4from
Quote:
word1_word2-word3@word4.word5
or
Quote:
word1_word2-word3@word4-word5
i can change that text .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output not coming as desired.

Hi guys. I have a file containing some hosts and their IPs. host host1 192.168.2.10 host host2 192.168.2.11 host host3 192.168.2.12 I am writing a script where I want to print these values in 1 line. My script looks like RUNTIME_NODE=`cat hosts.properties | grep host` for i in... (7 Replies)
Discussion started by: Junaid Subhani
7 Replies

2. Shell Programming and Scripting

Help!! needed to get the desired output

Am in need of your help to get the desired output. nameSECURITY.SERVICES.CONFIG:GETVALUEisPrefetchedNsAccessLast2013-09-13 10:50:13 MESTsAccessTotal1sRunningcHitLastnamePUBLIC.SERVER:INVOKEisPrefetchedNsAccessLast2013-09-17 15:02:05... (5 Replies)
Discussion started by: rocky2013
5 Replies

3. Shell Programming and Scripting

How to grep the desired output and output to a file?

currently I have process from a raw file to this stage ALTER TABLE "EXCEL_ADMIN"."TC_TXN_VOID" ADD CONSTRAINT "PK_TC_TXN_VOID" PRIMARY KEY ("TC_TXN_IID") ALTER TABLE "EXCEL_ADMIN"."TC_TXN_AMT" ADD CONSTRAINT "PK_TC_TXN_AMT" PRIMARY KEY ("TC_TXN_AMT_IID") ALTER TABLE... (10 Replies)
Discussion started by: jediwannabe
10 Replies

4. Shell Programming and Scripting

sed or awk, cut, to extract specific data from line

Hi guys, I have been trying to do this, but... no luck so maybe you can help me. I have a line like this: Total Handled, Received, on queue Input Mgs: 140 / 14 => 0 I need to, get the number after the / until the =, to get only 14 . Any help is greatly appreciated. Thanks, (4 Replies)
Discussion started by: ocramas
4 Replies

5. Shell Programming and Scripting

AWK command to cut the desired header columns

Hi Friends, I have a file1 i want to retrieve only the fields which have DEP,CITY,TRANS as headers in other file. Output: I want to give the input as DEP,CITY,TRANS column names to get the output. i used cut command .. but if i have 300 fileds it is more difficult to... (4 Replies)
Discussion started by: i150371485
4 Replies

6. Shell Programming and Scripting

need to get the desired output

Below is the my cide which is working fine but I am not getting the output indesired format.there is some problem in alignment.Can someone help me to correct this? if ]; then summary=$( echo -e "Please review the log file of auto coloclean utility.\n"; echo -e... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

7. Shell Programming and Scripting

SED - output not desired

echo '0x3f 0xfa ae 0xeA' | sed '/0x/ y/abcdef/ABCDEF/' output: 0x3F 0xFA AE 0xEA echo '0x3f 0xfa ae 0xeA' | sed -r '/0x{2}/ y/abcdefg/ABCDEFG/' output: 0x3F 0xFA AE 0xEA my expected output: 0x3F 0xFA ae 0xEA What I want to achieve is change all hexadecimals to UPPER case(only those... (6 Replies)
Discussion started by: kevintse
6 Replies

8. Shell Programming and Scripting

how to get desired output after redirection

hi i am running script which contains the commmnds and i am redirecting the script output to a file. like ./script 1> result.txt 2>&1 the above redirection is not working for commands when run in background in a script. but the problem here result.txt containg output which is repeated.... (3 Replies)
Discussion started by: raji
3 Replies

9. Shell Programming and Scripting

script not giving the desired output

Hi, I have a script in which an entry like this ..... FILENAME_B="PIC_${DATE}0732*.JPG" The script connects to an ATM and pull a pic file from it.The format for the file is like PIC_2008061400000001.JPG in the ATM. Means 1st 8 digit is the date(YYYYMMDD) field 2nd 8 digit means hrs... (2 Replies)
Discussion started by: Renjesh
2 Replies

10. Shell Programming and Scripting

Help me in getting the desired output

I wanted to put "|" this sign at starting and at end of every field but its not working with first field like Currently the out put is : abc | abc | abc | xyz | xyz | xyz | But I want the out put in this form: | abc | abc | abc | | xyz | xyz | xyz | plz help me. (2 Replies)
Discussion started by: akash
2 Replies
Login or Register to Ask a Question