How can i delete a keyword starting with x in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i delete a keyword starting with x in unix
# 1  
Old 07-23-2009
How can i delete a keyword starting with x in unix

I am trying to delete key word starting with x in a unix text file.
example, I am trying to delete the words like xaa,xabxbb,xbd and so on....

my input file is some thing like this
Code:
xaaa w 1234 5678
rwsd ravi xw123
xbc3 ohrd

want to delete words xaaa,xw123 and xbc3 from the above file...Please help
# 2  
Old 07-23-2009
try ..
Code:
awk 'gsub("x*","")' file

# 3  
Old 07-23-2009
It's not working Ryan...giving syntax error :-(
# 4  
Old 07-23-2009
Code:
sed 's/\(.*\)\(x[a-z]*[0-9]*\)\(.*\)/\1\3/'  file_name.txt

# 5  
Old 07-23-2009
Panyam, Its working gud..but i need to delete that line untill i find some space.for example i have input
Code:
xaa=grpsor29bb4:shelf=1:slot=1:pport=1:channel=1-4-4 aaaa

the output should be just aaaaPlease let me know how should i change the command that you have provided.
# 6  
Old 07-23-2009
Quote:
Originally Posted by rdhanek
It's not working Ryan...giving syntax error :-(
i'm not sure i'm using ubuntu.
Code:
ryandegreat25@ryandegreat25-desktop:~$ cat scrt
#!/bin/sh
awk 'gsub("x*","")' test 
ryandegreat25@ryandegreat25-desktop:~$ ./scrt
aaa w 1234 5678
rwsd ravi w123
bc3 ohrd
ryandegreat25@ryandegreat25-desktop:~$

try
Code:
awk 'gsub{"x*",""}' test



---------- Post updated at 09:57 PM ---------- Previous update was at 09:54 PM ----------

Quote:
Originally Posted by rdhanek
Panyam, Its working gud..but i need to delete that line untill i find some space.for example i have input
Code:
xaa=grpsor29bb4:shelf=1:slot=1:pport=1:channel=1-4-4 aaaa

the output should be just aaaaPlease let me know how should i change the command that you have provided.
well i'm not sure but maybe
Code:
awk '{print $NF}' file

# 7  
Old 07-23-2009
A small change will do the work :

Code:
sed 's/\(.*\)\(x[^ ]*\)\(.*\)/\1\3/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Search for a Keyword in file and replace another keyword or add at the end of line

Hi I want to implement something like this: if( keyword1 exists) then check if(keyword2 exists in the same line) then replace keyword 2 with New_Keyword else Add New_Keyword at the end of line end if eg: Check for Keyword JUNGLE and add/replace... (7 Replies)
Discussion started by: dashing201
7 Replies

2. Shell Programming and Scripting

Delete lines starting with these strings

Platform : RHEL 5.8 I have text file called myapplication.log . In this file, I have around 800 lines which start with the followng three strings PWRBRKER-3493 PWRBRKER-7834 SCHEDULER-ERROR How can I delete these lines in one go ? (13 Replies)
Discussion started by: omega3
13 Replies

3. Shell Programming and Scripting

Displaying all the lines starting with some keyword

consider the contents of a file has many stuff including few stuff that i need.. so i perfromed the below function cat filename | grep "ALTER TABLE" its output is as shown below . . . . . SET @sql:=CONCAT('ALTER TABLE RecordMixProfile AUTO_INCREMENT=', @maxId) ; SET... (14 Replies)
Discussion started by: vivek d r
14 Replies

4. Shell Programming and Scripting

Using sed to delete a line having a particular keyword

Hi Geeks :b:, I need to delete a line from file that contains a particular keyword. I had read in some forum of unix.com that below code could be used sed "/$titlesearch/d" movielist >tmp mv tmp movielist But my file contains lines which contain slashes (/) FOr eg: /etc/movie/title/... (5 Replies)
Discussion started by: ajincoep
5 Replies

5. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

6. Shell Programming and Scripting

How can i delete a keyword containing XYZ in unix

Hi all, I am trying to remove the words which has XYZ as a prt of that. My input file is something like this : PHNDAZLF-UPS-XYZ' aaaaaaa bbbbb ADFRTEJKS-XYZ cccccccc ddddddd rrrrrr SGETHEHDJ-ABC-RXY' hhhhh ttttt' kkkk FHJSKSJDKD-XXX-YYY Output expected is : aaaaaaa... (7 Replies)
Discussion started by: rdhanek
7 Replies

7. Shell Programming and Scripting

search for keyword in subsequent lines and delete the second line

I have my data something like this I need to search for the keyword yyyy in the susequent lines and if it is present, delete the second line with keyword. In other words, if a keywords is found in two subsequent lines delete the second line. input data: aaaa bbbbb cccc dddd xxxx... (4 Replies)
Discussion started by: rdhanek
4 Replies

8. Shell Programming and Scripting

Delete the lines before the first instance of the keyword

I have my data something like this. I want to delete all the lines before the frist instance of the key word 'ravi kumar' aaa bbbbbb cccccc ddddd eeeee 1234 ravi kumar aaaaaa vvvvvvv 5678 ravi kumar rrrrrrr mmmmmmm I want the output as follows. 1234 ravi kumar aaaaaa... (8 Replies)
Discussion started by: rdhanek
8 Replies

9. Shell Programming and Scripting

Delete the lines after the last instance of the keyword

I have my input sometyhing like this aaa bbbbbb cccccc ddddd eeeee 1234 ravi kumar aaaaaa vvvvvvv 5678 ravi kumar rrrrrrr mmmmmmm I want the output as follows. aaa bbbbbb cccccc ddddd eeeee 1234 ravi kumar aaaaaa vvvvvvv 5678 ravi kumar (2 Replies)
Discussion started by: rdhanek
2 Replies

10. Shell Programming and Scripting

Delete lines starting with XX or YY or ZZ or ....

Hi There! My final task for today is to delete lines starting with certain numbers for e.g., my text block is and i want to delete all lines starting with 11 or 17 or 21 I know i can use multiple sed commands like sed '/^11,/d' <filename> sed '/^17,/d' <filename> sed '/^21,/d'... (2 Replies)
Discussion started by: orno
2 Replies
Login or Register to Ask a Question