Remove a substring from string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove a substring from string
# 1  
Old 03-11-2013
Remove a substring from string

Good morning friends,

how can i remove a string with linux scripting from a file? In specific i want to remove from a file all the tweet names and links
eg
@aerta and links such as http://dst.co/pIiu3i9c

Thanx!!!
# 2  
Old 03-11-2013
Code:
sed -e "s?http://[^ ]*??g" -e "s/@aerta//g" file

This User Gave Thanks to anbu23 For This Post:
# 3  
Old 03-11-2013
anbu23's proposal is fine, but you may want to replace s/@aerta//g by s/@[^ ]*//g so your script will be more generic.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 03-11-2013
Quote:
Originally Posted by anbu23
Code:
sed -e "s?http://[^ ]*??g" -e "s/@aerta//g" file

Thanks for the replay it seems to work for the links but the usernames can be anything... not just @aerta

Thanks for your reply!!!

---------- Post updated at 03:01 AM ---------- Previous update was at 02:59 AM ----------

That is exactly what i wanted!!! Thanks, have a nice day!!
# 5  
Old 03-11-2013
A perl:
Code:
perl -pe 's/@\S+|http:\/\/\S+//g' infile

This User Gave Thanks to Klashxx 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

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Remove lines matching a substring in a specific column

Dear group, I have following input text file: Brit 2016 11 18 12 00 10 1.485,00 EUR Brit 2016 11 18 12 00 10 142,64 EUR Brit 2016 11 18 12 00 10 19,80 EUR Brit 2016 11 18 12 00 10 545,00 EUR Brit 2016 11 18 12 00 10 6.450,00 EUR... (3 Replies)
Discussion started by: gfhsd
3 Replies

3. UNIX for Dummies Questions & Answers

Remove when substring meets condition

Hi Masters, I need to remove lines when date format is below certain date My file input 20140906|ALASKA|USASEL|TARPUNG|2014-03-01|82176614040|20|1 20140906|ALASKA|USATENG|CRUIEX|2014-08-01|81267079997|5|0 20140906|ALASKA|USASEL|CRUIEMBANG|2013-10-01|82280779814|9|0... (4 Replies)
Discussion started by: radius
4 Replies

4. Shell Programming and Scripting

Using sed, awk or perl to remove substring of all lines except the first

Greetings All, I would like to find all occurences of a pattern and delete a substring from the all matching lines EXCEPT the first. For example: 1234::group:user1,user2,user3,blah1,blah2,blah3 2222::othergroup:user9,user8 4444::othergroup2:user3,blah,blah,user1 1234::group3:user5,user1 ... (11 Replies)
Discussion started by: jacksolm
11 Replies

5. Shell Programming and Scripting

how to remove this substring?

Hello, I need to remove a substring from a string in a ksh script, the string is like this: LOCATION=+DATADG1/CMSPRD1/datafile/system.235.456721 or LOCATION=/u03/oradata/CMSPRD/SYSTEM.dbf I need to strip the last file name from that path, and get: +DATADG1/CMSPRD1/datafile or,... (8 Replies)
Discussion started by: seafan
8 Replies

6. Shell Programming and Scripting

Help with string and substring also I/O

#!/bin/sh PRINTF=/usr/bin/printf PASSWD=/etc/passwd $PRINTF "Enter a UserID\n" read USERID if ; then $PRINTF "$USERID does not exist, please contact IT service\n" exit 1 fi USERHOME=`grep "^$USERID:" $PASSWD | awk -F : '{print $6}'` USERSHELL=`grep "^$USERID:"... (1 Reply)
Discussion started by: ikeQ
1 Replies

7. Shell Programming and Scripting

how to remove a substring

I want to modify a string in shell script (/bin/sh). Could you please help me. I have a variable which can store the values like below. v10.5.2.1p001C_TN1 or v10.5.2.1p002_TN1 I have to search first whether ‘p' character exists into the string which is stored in a variable..... (5 Replies)
Discussion started by: samtekdallas
5 Replies

8. Shell Programming and Scripting

get substring from string

Hi All, Problem Description: XML_REP_REQUEST=`CONCSUB "$LOGIN" "SQLAP" "$RESP_NAME" "$USRNM" WAIT="Y" "CONCURRENT" "APPLICATION_SHORT_NAME" "CP_SHORT_NAME"` echo Report Request: $XML_REP_REQUEST --to print value in log file While execution the value of 'XML_REP_REQUEST' is 'Prozess... (5 Replies)
Discussion started by: suman.g
5 Replies

9. Shell Programming and Scripting

getting a substring from a string

hi all, I am trying to extract SUBSTRINGS out of a string using ksh. The string is "SAPR3K.FD0.FA.TJ.B0010.T050302" I tried using a= `expr substr $stringZ 1 2` which is giving me a syntax error, donno why?? any ideas why its not working?? I also tried echo "welcome" | awk '{... (3 Replies)
Discussion started by: maradona
3 Replies

10. Programming

can i get a substring from a string?

for example, the string a is "abcdefg", can i get a substring "bcd" (from ato a) from string a? thank you (4 Replies)
Discussion started by: dell9
4 Replies
Login or Register to Ask a Question