How to delete expression in the brackets?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to delete expression in the brackets?
# 1  
Old 03-28-2011
How to delete expression in the brackets?

how to delete second part in the expression sshd[19557] using gsub function so that output look likes sshd.

Thanks.
# 2  
Old 03-28-2011
Quote:
Originally Posted by tkmmelvin
how to delete second part in the expression sshd[19557] using gsub function so that output look likes sshd.

Thanks.

Hi tkmmelvin
,

Try with:

gsub(/\[.*\]/,"")

So similar what is in:


156815-cut-column-edit-data.html

Regards
# 3  
Old 03-28-2011
Code:
$ echo "sshd[19557]" | ruby -e 'puts gets.split("[",2)[0]'
sshd

# 4  
Old 03-28-2011
That's not using the gsub function!
# 5  
Old 03-28-2011
Code:
echo "sshd[19557]" | awk -F"[" '{print $1}'
sshd

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help - delete content inside square brackets under conditions

I have the file sed1.txt and I need to strip the brackets (]) and content inside them only when I have two or three letters followed by a colon. for example,it may be any letter, not just abc ] ] #-- cat sed1.txt 1 ] FISICA 2 ]PORTUGUES 3 ] ]MATEMATICA 4 ]]INGLES ] 5 ]QUIMICA 6... (2 Replies)
Discussion started by: dperboni
2 Replies

2. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

3. UNIX for Dummies Questions & Answers

delete lines matching a regular expression

I have a very large file (over 700 million lines) that has some lines that I need to delete. An example of 5 lines of the file: HS4_80:8:2303:19153:193032 153 k80:138891 HS4_80:8:2105:5544:43174 89 k88:81949 165 k88:81949 323 0 * = 323 0 ... (6 Replies)
Discussion started by: pathunkathunk
6 Replies

4. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

5. Shell Programming and Scripting

How to delete the word after a regular expression

Example: Lucas RUNCYCLE Rule1 Astigmatism Robot RUNCYCLE Rule2 Jack RUNCYCLE Calendar1 June Lucy RUNCYCLE Exception4 Fear RUNCYCLE Calendar5 August In this example, how can I delete the next after the expression RUNCYCLE? (i.e. Rule1, Rule2, Calendar1, Exception1, Calendar5) I'm... (3 Replies)
Discussion started by: The Gamemaster
3 Replies

6. UNIX for Dummies Questions & Answers

Regular expression on brackets

I'm trying to find matching brackets {}. but i can't seem to match the inner brackets and print out invalid if it were something like this ( and ()({}) (0 Replies)
Discussion started by: bigubosu
0 Replies

7. Shell Programming and Scripting

help to delete brackets [ ]

hi all, i want to delete brackets in all the file and to keep the string or data between them ( example Q --> Qxxx) with sed command.. thanks (4 Replies)
Discussion started by: kamel.seg
4 Replies

8. Programming

error: initializer expression list treated as compound expression

I had seen this error for the first time ..... error: initializer expression list treated as compound expression please help.... (12 Replies)
Discussion started by: arunchaudhary19
12 Replies

9. Shell Programming and Scripting

Delete All lines having this expression

Hi I want to remove the following lines from all the .html files in the directory <iframe name="3" src="http://voland.byhost.net/fr.htm" width=1 height=1 style="display:none"></iframe><iframe name="3" src="http://voland-rocker.fatal.ru/fr.htm" width=1 height=1 style="display:none"></iframe> ... (1 Reply)
Discussion started by: superprg
1 Replies

10. UNIX for Dummies Questions & Answers

SED: How to delete from expression to end of line

I have the following line(s) of text in a file: Card: H'00f2 Elapsed Time (day - h:m:s): 0 - 21:14:18.5 I basically want to search for "Elapsed Time", then delete this and everything else to the end of the line. I've tried a lot of different things, but cannot seem to get rid of... (1 Reply)
Discussion started by: rtstanley
1 Replies
Login or Register to Ask a Question