Remove word with sed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove word with sed
# 1  
Old 03-11-2014
Remove word with sed

How can I use sed or any utility to remove any word that begins with TRS-, I have tried sed
Code:
's/ERA.*//g'

but seems not to be working
Input:

Code:
23 TRS-458-9 345 235
45 TRS-42-5 423 000
76 300 234

Output:

Code:
23 345 235
45 423 000
76 300 234

# 2  
Old 03-11-2014
Code:
$ sed "s/TRS-[^ ]* //g" file
23 345 235
45 423 000
76 300 234

This User Gave Thanks to anbu23 For This Post:
# 3  
Old 03-11-2014
Thanks
# 4  
Old 03-11-2014
Hello,

One more solution for same.

Code:
awk '{for(i=1;i<=NF;i++) {if($i !~ /TRS/) {print $i}}}' file_name | xargs -n 3

Output will be as follows.

Code:
23 345 235
45 423 000
76 300 234


Thanks,
R. Singh
# 5  
Old 03-11-2014
Using the same regex via awk
Code:
awk '{sub(/TRS-[^ ]* /,x)}1' infile

# 6  
Old 03-11-2014
Or maybe a different approach could be used:
Code:
awk '{print $1, $(NF-1), $NF}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Please remove the word from posts

Hi Sir, Need your help in removing the following words from the posts . These are confidential info posted by mistake and our organization is doing an audit on this. Could you kindly remove as per below. https://www.unix.com/shell-programming-and-scripting/197017-perl-help.html ... (4 Replies)
Discussion started by: ptappeta
4 Replies

2. Shell Programming and Scripting

Bash - sed - Remove first word from line which can begin eventually with blank

hello. How to remove first word from line. The line may or may not start with blank. NEW_PARAM1=$(magic-command " -t --protocol=TCP -P 12345-u root -h localhost ") NEW_PARAM2=$(magic-command "-t --protocol=TCP -P 12345 -u root -h localhost ") I want NEW_PARAM1 equal to NEW_PARAM2 equal ... (2 Replies)
Discussion started by: jcdole
2 Replies

3. Shell Programming and Scripting

Remove word before a character

Hi, I have a file which looks like this id integer, name string, create_dt date, I want to remove all words that are present before the character , My output should be id, name, create_dt, Thanks wah (2 Replies)
Discussion started by: wahi80
2 Replies

4. Shell Programming and Scripting

Replacing a particular word with another word in all the xml's under a particular directory with sed

Hi Folks, Could you please advise what will be the SED command to replace a word in all xml's under a particular directory for example let say I rite now at the following below location $ cd /ter/rap/config now under config directory there will be lots of xml file , now my objective is to... (1 Reply)
Discussion started by: punpun66
1 Replies

5. Shell Programming and Scripting

How to remove first word?

Hi All, I want to remove the first word "cn=" from the below details. Only I want the number like 171345,174144... cn=171345 cn=174144 How can I achieve this. Please suggest. Thanks- P (6 Replies)
Discussion started by: pokhraj_d
6 Replies

6. Shell Programming and Scripting

sed command to remove a word from string

Hello All, I am running a command find . -name amp.cfg | cut -c 3- which gives me output something like below rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like... (7 Replies)
Discussion started by: anand.shah
7 Replies

7. UNIX for Dummies Questions & Answers

How to print line starts with specific word and contains specific word using sed?

Hi, I have gone through may posts and dint find exact solution for my requirement. I have file which consists below data and same file have lot of other data. <MAPPING DESCRIPTION ='' ISVALID ='YES' NAME='m_TASK_UPDATE' OBJECTVERSION ='1'> <MAPPING DESCRIPTION ='' ISVALID ='NO'... (11 Replies)
Discussion started by: tmalik79
11 Replies

8. Shell Programming and Scripting

want to remove last word.

Hi, I have a file which has the following /u12/data/oracle/abc.dbf /u12/data/oracle/def.dbf /u12/data/oracle/daf.dbf /u12/data/oracledb/fgh.dbf /u12/data/oracledb/fkh.dbf /u12/data/oracledb/kdq.dbf I want to do something like this /u12/data/oracle /u12/data/oracle... (7 Replies)
Discussion started by: javeedkaleem
7 Replies

9. Shell Programming and Scripting

Remove particular word from file

Hi All, If my file is: Wed Sep 9 22:45:14 EDT 2009 sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> sftp> This is log file generated from transfer... sftp> sftp> sftp> sftp> Files placed properly.... sftp> sftp> sftp> How can I remove "sftp>" word from this... (4 Replies)
Discussion started by: darshakraut
4 Replies

10. Shell Programming and Scripting

how to remove first word

Hi, i have a question about to remove first word from a sentence. my script; #!/usr/bin/perl $msgtxt = "this is a test script"; my @ap_txtMsg = split(/ +/, trim_data($msgtxt)); $ap_msgtxt = splice (@ap_txtMsg, 0, 1); print $ap_msgtxt; but the output is first word that i... (1 Reply)
Discussion started by: malaysoul
1 Replies
Login or Register to Ask a Question