Bash: delete phrase from string
Hello Community,
I have a string of words, "hello my name is batman", and i want to delete my name is from the string. I want to automate this process so that I can use it with other strings (ie. "hello my name is Robin"), but i don't want to be cutting characters because it is a different amount of characters for each one (it's obviously not as simple as "hello my name is..."). Thank you so much.
The OP wants to delete 'batman', or any name after "is ", so:
echo "hello my name is batman" | sed 's/\(hello my name is \).*/\1/'
This will work on any name:
echo "hello my name is Robin" | sed 's/\(hello my name is \).*/\1/'
Tony
Similar Messages
-
hi,
i have field like that 12-3456
and i wont to delete '-' to have 123456
what is the best way to do that?
RegardsHi,
TRANSLATE field USING '- '.
CONDENSE field NO-GAPS.
The TRANSLATE command replaces al '-' with blanks and the CONDENSE, NO-GAPS compresses the string to remove all spaces/blanks.
Cheers,
Aditya -
I have a string of text sms and iMessages that I would like to save and then delete them from my phone, but gain access to them later if I need them. I prefer to have the string with the date/time stamp vs copying and pasting into a doc or text file. Is this possible?
Not unless you buy an app that accesses data from an iTunes backup. Check in the app store.
-
Delete a char from string ?
Hi,
I want to delete a char from string. i used the following function.
String f = formulla.replace('[','');
The above function doesnt work as it tells me to put a space or some char in 2nd parameter which i dont want. i just want to delete all occurences of some specific char in a string.
Any suggestion.
Thanks alot.u can do:
String before;
char charToReplace;
StringBuffer tempBuf = new StringBuffer(before);
for (int i=0; i<tempBuf.length(); i++)
if (tempBuf.charAt(i)==charToReplace)
tempBuf.deleteCharAt(i);
String after = tempBuf .toString(); HTH
Yonatan -
Hi,delete file from folder?
hi,i am deleting file from folder as follwos
<%@ page import="java.io.File" %>
<%
File myFile = new File("D:\\jakarta-tomcat-4.1.18\\webapps\\ROOT\\upload_files\\xyz.txt");
myFile.delete();
%>
i am sucessfuly deleted file from above path.
if i use follwing code i unable to delete my file, can one help,
how to do it,
<%@ page import="java.io.File" %>
<%
String fname="xyz.txt";
File myFile = new File("D:\\jakarta-tomcat-4.1.18\\webapps\\ROOT\\upload_files\\'"+fname+"'");
myFile.delete();
%>
thanks
pullareddyi think if above doesn't work try this it should work
change this line
File myFile = new File("D:\\jakarta-tomcat-4.1.18\\webapps\\ROOT\\upload_files\\'"+fname+"'");
to this
File myFile = new File("D:\\jakarta-tomcat-4.1.18\\webapps\\ROOT\\upload_files\\"+fname); -
Delete file from folder only (not from list)
Hi all,
I've searched a lot and didn't succeed so far, that's why I need your help. In a cloud context, I'm actually creating and uploading files (pdf and/or xml files) "on the go" to sharepoint folders via the SOAP API and this is perfectly working. But
in a cloud context, I also need to decomission services which is translated into deleting files into Sharepoint.
That's where it became complicated, because according to the API we cannot delete files if they are not part of a list structure, which is not my case. Is that true ?
The only info I have when trying to delete a file via the SOAP Api is : its name, its folder, and the endpoint where the folder is. So my question remains simple I guess : is this possible ? If so, how to (a link to the SOAP body would be usefull)
Thanks a lot
Regards
BaptisteHi,
According to your post, my understanding is that you want to delete file from folder.
In SharePoint 2010, It is recommended to use Client Object Model to achieve it, the following code snippet for your reference:
string siteURL = "http://siteurl";
ClientContext context = new ClientContext(siteURL);
//specific user
NetworkCredential credentials = new NetworkCredential("username", "password", "domain");
context.Credentials = credentials;
Web web = context.Web;
context.Load(web);
context.ExecuteQuery();
string relativeUrl =web.ServerRelativeUrl +"/DocumentLibraryName/FolderName/FileName";
File file = web.GetFileByServerRelativeUrl(relativeUrl);
context.Load(file);
file.DeleteObject();
context.ExecuteQuery();
If you still want to use SOAP API, we can use the UpdateListItems method under Lists web service to achieve it.
http://www.dhirendrayadav.com/2010/06/delete-list-items-using-web-service.html
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/61466984-1844-48a1-8c1e-1c59a0f9876a/move-and-delete-files-remotely-using-sharepoint-web-services-?forum=sharepointdevelopmentlegacy
Thanks,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Dennis Guo
TechNet Community Support -
How to delete images from folder which are not in the database
I am created windows form
i wont to delete images from the folder where i have stored images but i only want to delete those images which are not in the data base.
i don't know how it is possible . i have written some code
private void button1_Click(object sender, EventArgs e)
string connectionString = "Data Source";
conn = new SqlConnection(connectionString);
DataTable dt = new DataTable();
cmd.Connection = conn;
cmd.CommandText = "select * from tbl_pro";
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
int count = Convert.ToInt32( dt.Rows.Count);
string[] image1 = new string[count];
for (int i = 0; i < count; i++)
image1[i] = dt.Rows[i]["Image1"].ToString();
string[] image2 = new string[count];
for (int i = 0; i < count; i++)
image2[i] = dt.Rows[i]["Image2"].ToString();
var arr = image1.Union(image2).ToArray();
string[] arrays;
String dirPath = "G:\\Proj\\";
arrays = Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories).Select(x => Path.GetFileName(x)).ToArray();
int b= arrays.Count();
for (int j = 1; j <= b; j++)
if (arrays[j].ToString() != arr[j].ToString())
var del = arrays[j].ToString();
else
foreach (var value in del) // ERROR DEL IS NOT IN THE CURRENT CONTEXT
string filePath = "G:\\Projects\\Images\\"+value;
File.Delete(filePath);
here error coming "DEL IS NOT IN THE CURRENT CONTEXT"
I have to change anything .Will It work alright?
pls help me
SmsHi Fresherss,
Your del is Local Variable, it can't be accessed out of the if statement. you need to declare it as global variable like below. And if you want to collect the string, you could use the List to collect, not a string. the string will be split to chars
one by one.
List<string> del=new List<string>();
for (int j = 1; j <= b; j++)
if (arrays[j].ToString() != arr[j].ToString())
del.Add(arrays[j].ToString());
else
foreach (var value in del)
string filePath = "G:\\Projects\\Images\\" + value;
File.Delete(filePath);
If you have any other concern regarding this issue, please feel free to let me know.
Best regards,
Youjun Tang
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Hi there,
I am having a real battle trying to delete data from a text file I am using. There seems to be this giant cloud with Java, where there is no real easy way to delete text from a file??
I have a JFrame with two textfields on it where you enter the username and pcname. There is a OK button once you have entered those details.
On action event I would like those two details, to be removed from the text file that has been read in.
I have a text file like this:
bob
pc1
bill
pc2
The data above gets written no problem, one at at a time using the below.
File f = new File("\\c:\\filename.txt");
String strToWrite;
try
FileOutputStream fstr = new FileOutputStream(f);
strToWrite = username1+ '\r'+'\n' ;
byte[] bytes = strToWrite.getBytes(); fstr.write(bytes);
strToWrite = pcname1 + '\r'+'\n' ;
byte[] bytes2 = strToWrite.getBytes(); fstr.write(bytes2);
strToWrite = username2+ '\r' +'\n' ;
byte[] bytes3 = strToWrite.getBytes(); fstr.write(bytes3);
strToWrite = pcname2 + '\r'+'\n' ;
byte[] bytes4 = strToWrite.getBytes(); fstr.write(bytes4);
catch (IOException e)
System.out.println("Error -- " + e.toString());
To read them back in I have made the follwoing:
BufferedReader br= null;
Count = 0;
try
br = new BufferedReader(new InputStreamReader(new FileInputStream("\\c:\\filename.txt")));
String s = "";
while((s=br.readLine()) != null )
Count = 1;
//System.out.println("Data is " + s);
inboundtext = s;
if ( Count == 1 )
break;
while((s=br.readLine()) != null )
//System.out.println("Data is " + s);
inboundtext = s;
Count = 2;
if ( Count == 2 )
break;
catch(IOException ie)
finally
try
if(br!=null) br.close();
catch(Exception e)
Now the above I know, is reading each line of the text file one at a time.
Now what I would like is that when the text that we got from the textfields, using getText(), be removed from the file without destroying the rest of the records in there? Why is it so easy to add and replace files, but not do any deleting from them?
please help!!sorry, FileOutputStream fstr = new FileOutputStream(f);
should be FileOutputStream fstr = new FileOutputStream(f, true); -
How to choose in Delete Duplicates from internal table?
Now I need to delete Duplicates from internal table,
So at first I sort
than I delete duplicate
Sort itab1 BY Company_Code Asset_No Capital_Date.
DELETE ADJACENT DUPLICATES FROM itab1 COMPARING Company_Code Asset_No Capital_Date
Company_Code
Asset_No
Capital_Date
Remark
BC35
1515593
20021225
Helen
BC35
1515593
20021225
Common Asset
BC35
1515594
20030109
Judy
BC35
1515594
20030109
Common Asset
But here comes my problem~If I want to delete the Common Asset in Remark Column,how I let it choose the right one to do it?Hi Jack
Try the below coding..
Report zsamp.
types: begin of t_tab,
comp_code(4) type c,
***_no(7) type n,
cap_date type d,
remark type string,
end of t_tab.
data: i_tab type TABLE OF t_tab,
w_tab type t_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515593'.
w_tab-cap_date = '20021225'.
w_tab-remark = 'Helen'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515593'.
w_tab-cap_date = '20021225'.
w_tab-remark = 'Common Asset'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515594'.
w_tab-cap_date = '20030109'.
w_tab-remark = 'Judy'.
append w_tab to i_tab.
w_tab-comp_code = 'BC35'.
w_tab-***_no = '1515594'.
w_tab-cap_date = '20030109'.
w_tab-remark = 'Common Asset'.
append w_tab to i_tab.
sort i_tab by remark.
delete ADJACENT DUPLICATES FROM i_tab COMPARING remark. -
How do I delete text from a textArea?
How do I delete text from a textArea? I basically want the opposite of append(String)... I want something that removes a line from my TextArea. Anyone know?>
If you want to remove only a specific part of the text, you have to get the String, take the parts before and after the removed part, append them back together and use setText to replace it in the textArea.
-
How do I archive emails in mail and then delete them from my inbox?
I need to archive a bunch of emails for a project, and I know that if I put them in a mailbox and then delete them from my inbox, they're gone. So, what's the most efficient way to save 100s of emails that will eventually need to be filed within a project file?
// Sample code
List resList = new Vector();
MyObject obj = null;
while(rs.next()) {
obj.setXXX(rs.getXXX(i)); // Get from the resultset and set to the object
resList.add(obj);
// At the end of the loop, you have a Vector of objects holding data.What do you mean by returning Strings separately? -
Deleting records from child to parent table
I have ran into a situation where i will have to delete all the records of the child table and then the records of parent table and i was able to write a query to get the column,table both for parent,child and stuck up in deleting them using query and
i will not be able to use Cascade...My validation criteria is applicable for the child tables and parent table...am trying to compare last modified date of each table...Kindly help me with an approach
DECLARE @mytable VARCHAR(30) SET @mytable = 'tablea'
DECLARE @Order INT SET @Order = 0
DECLARE @Count INT
declare @tblname varchar(100),@query NVARCHAR(max),@parent varchar(100)
if OBJECT_ID('tempdb..#OrderList','U') is not null
DROP TABLE #OrderList
if OBJECT_ID('tempdb..#temp','U') is not null
DROP TABLE #temp
CREATE TABLE #TEMP
OrderNo INT,
TableName VARCHAR(50),
tid varchar(100),
childtable varchar(100),
cid varchar(100)
CREATE TABLE #OrderList
RecordNo INT,
OrderNo INT,
TableName VARCHAR(50),
tid varchar(100),
childtable varchar(100),
cid varchar(100)
create table #t
taname varchar(100)
;with tempcte (level,parent,pcol,child,ccol)
as
SELECT 0,SO2.name, SC2.name,SO1.name, SC1.name
FROM dbo.sysforeignkeys FK
INNER JOIN dbo.syscolumns SC1
ON FK.fkeyid = SC1.id AND FK.fkey = SC1.colid
INNER JOIN dbo.syscolumns SC2
ON FK.rkeyid = SC2.id AND FK.rkey = SC2.colid
INNER JOIN dbo.sysobjects SO1
ON FK.fkeyid = SO1.id
INNER JOIN dbo.sysobjects SO2
ON FK.rkeyid = SO2.id
INNER JOIN dbo.sysobjects FO
ON FK.constid = FO.id
WHERE SO2.Name = 'tablea'
union all
SELECT level+1,SO2.name, SC2.name,SO1.name, SC1.name
FROM dbo.sysforeignkeys FK
INNER JOIN dbo.syscolumns SC1
ON FK.fkeyid = SC1.id AND FK.fkey = SC1.colid
INNER JOIN dbo.syscolumns SC2
ON FK.rkeyid = SC2.id AND FK.rkey = SC2.colid
INNER JOIN dbo.sysobjects SO1
ON FK.fkeyid = SO1.id
INNER JOIN dbo.sysobjects SO2
ON FK.rkeyid = SO2.id
INNER JOIN dbo.sysobjects FO
ON FK.constid = FO.id
inner join tempcte t
on SO2.Name = t.child
insert into #TEMP
OrderNo,
TableName,
tid,
childtable,
cid
select
level,parent,pcol,child,ccol from tempcte
select * from #TEMP
INSERT INTO #OrderList
SELECT Row_number() OVER (ORDER BY OrderNo, TableName),
#TEMP.OrderNo,
#TEMP.TableName,
#TEMP.tid,
#temp.childtable,
#TEMP.cid
FROM #TEMP
SET @Count = (SELECT Max(RecordNo)
FROM #OrderList)
select * from #OrderListAm looking for a logic to delete the records..Please provide some query to better understand..
Thats easy, refer the below link: You may check string and then execute if everything looks ok to you.
Ref:http://social.msdn.microsoft.com/Forums/en-US/bc36c6b6-1aca-43aa-bc95-7518fdb6fe4c/delete-data-from-multiple-tables?forum=transactsql
declare @Deletecommand varchar(max)
;with object_cte(tblid,tblname,rtblid,rtblname,level)
as
select distinct o.object_id as tblid,OBJECT_NAME(o.object_id) as tblname,cast(null as int),cast(null as sysname),
0 as level
from sys.objects o
inner join sys.foreign_keys f
on f.parent_object_id = o.object_id
where o.is_ms_shipped=0
and o.type='u' and OBJECT_NAME(o.object_id) like '/BIO/A%'
union all
select t.object_id as tblid,OBJECT_NAME(t.object_id) as tblname,o.tblid,o.tblname,o.level + 1
from object_cte o
inner join sys.foreign_keys f
on f.parent_object_id = o.tblid
join sys.objects t
on t.object_id = f.referenced_object_id
where t.is_ms_shipped=0
and t.type='u'
and OBJECT_NAME(o.object_id) like '/BIO/A%'
select @Deletecommand =(select 'DELETE FROM ' + tblname + ';' from
select row_Number() over (partition by tblname order by level) as rn,* from object_cte
)t
where rn=1
order by level
for xml path(''))
print @Deletecommand
--exec (@Deletecommand) -
Error 116 at Unflatten from string.....
Hi I want to save and load the control values of
the tab pages I am getting the following error
"Error 116 occurred at Unflatten From String
Unflatten or byte stream read operation
failed due to corrupt, unexpected, or truncated data."
the attached is the VI can
anyone tell me what is wrong ….thank you
Attachments:
save n load example.vi 70 KBAll that you need to do is right-click on the Read from Text File and Write to Text File functions and uncheck "Convert EOL".
Other comments:
You should not hard-code the path inside the VI. Either place a front panel control to specify the path (perhaps with a default value set), or generate the path so that it is relative to the VI (such as being in the same directory as the VI).
You are not wiring all your errors through so some errors can be lost.
You do not need to have the VI open a reference to itself. If you delete the Open VI Reference function the code will still work. -
Delete service from dba_services
Hi,
I have my Production database running on 11.1.0.7 environment running on Oracle Enterprise Linux 64 bit.
Please help me clarify the doubts on database services
SQL > select name from dba_services;
NAME
SYS$BACKGROUND
SYS$USERS
seeddataXDB
seeddata
MYCSMR.example.com
CONSUM
CONSUM_SEARCH
MYCSMA.example.com
QUICKSURVEY
QUICKSURVEY.example.com
10 rows selected.
SQL > sho parameter service
NAME TYPE VALUE
service_names string CONSUM, CONSUM_SEARCH, MYCSMA.
example.com, QUICKSURVEYI see this additional 2 services on dba_services view -> i.e. MYCSMR.example.com & QUICKSURVEY.example.com
Any pointers as to how I delete them from the dba_services view?
Thanks!Hi,
You can check from v$session and see if any session is using the services using SERVICE_NAME in where clause. Below is the script for 3-node rac to check the service name and the number of sessions coming in using them
prompt Total Sessions by Service
select service_name "Service",
count(*) "Total Sessions",
sum(decode(se.inst_id,1,1,0)) "Inst 1",
sum(decode(se.inst_id,2,1,0)) "Inst 2",
sum(decode(se.inst_id,3,1,0)) "Inst 3"
from gv$session se
group by service_name
order by service_name;You can also check V$ACTIVE_SERVICES and V$active_session_history and also join then using SERVICE_HASH and NAME_HASH column.
Anand -
Delete rows from table...Bizarre problem.
Folks
i HAVE this bizarre problem.
I hava a Java class which displays data read into a table with a delete
option by the side of each row.
Now lets assume you have 3 rows in the Table.
abc deleteButton
efg deleteButton
xyz deleteButton
When I click the first delete,that row gets deleted from the table.(perfect...)
Now I have 2 rows.
When I click on the first row,I get the error
'You clicked -1'
java.lang.ArrayIndexOutofBoundsException: -1 < 0.
Can anyone tell me why this is happening even though there are rows in the table.???
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println("You clicked row : " + table.getSelectedRow());
javax.swing.table.TableModel model = table.getModel();
Object o = model.getValueAt(table.getSelectedRow(),0);
//System.out.print(model.getValueAt(table.getSelectedRow(), 0));
//System.out.println();
MyDeleteFunction(o.toString());
// Delete row from window.
((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
table.revalidate();
table.repaint();Hi ritu,
This class is called
new DisplayCall_IDTodisconnect(hashTable);
its a long file.
its attached below.
The rows are displayed by reading a hashtable into a vector
and the vector is iterated and appended..
public class DisplayCall_IDToDisconnect {
public static JTable createTable(Vector data, String buttonLabel, ActionListener action){
return createTable(data.iterator(), buttonLabel, action);
public static JTable createTable(
Iterator dataIterator,
String buttonLabel,
ActionListener action) {
DefaultTableModel model = new DefaultTableModel() {
public boolean isCellEditable(int row, int col) {
return col == 1;
model.setColumnCount(2);
while (dataIterator.hasNext()) {
Object[] row = { dataIterator.next().toString(), null };
model.addRow(row);
DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
columnModel.addColumn(new TableColumn(0, 100));
columnModel.addColumn(new TableColumn(1, 80,
new TableButtonCellRenderer(buttonLabel),
new TableButtonCellEditor(buttonLabel, action)
JTable table = new JTable(model, columnModel) {
public void valueChanged(ListSelectionEvent e) {
super.valueChanged(e);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
return table;
private static class TableButtonCellRenderer implements TableCellRenderer {
final JButton button;
TableButtonCellRenderer(String buttonLabel) {
button = new JButton(buttonLabel);
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus, int row, int column) {
return button;
private static class TableButtonCellEditor
extends AbstractCellEditor
implements TableCellEditor, ActionListener {
final JButton button;
final ActionListener callback;
TableButtonCellEditor(String buttonLabel, ActionListener callback) {
button = new JButton(buttonLabel);
this.callback = callback;
button.addActionListener(this);
public Component getTableCellEditorComponent(
JTable table,
Object value,
boolean isSelected,
int row, int column) {
return button;
public Object getCellEditorValue() {
return null;
public void actionPerformed(ActionEvent e) {
button.getParent().requestFocus();
callback.actionPerformed(e);
static JTable table;
Vector items;
final ClientManager clientMgr;
// Constructor.
public DisplayCall_IDToDisconnect(Hashtable callLegTable,ClientManager clientMgr){
Vector vCSeqnos = displayCSeqNos(callLegTable);
this.clientMgr = clientMgr;
JFrame frame = new JFrame("Disconnect Options");
/*Vector*/ items = new Vector();
Enumeration vEnum = vCSeqnos.elements();
while(vEnum.hasMoreElements()){
items.add(vEnum.nextElement());
ActionListener al = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("You clicked row ,col: " + table.getSelectedRow()+
// table.getSelectedColumn());
javax.swing.table.TableModel model = table.getModel();
Object o = model.getValueAt(table.getSelectedRow(),0);
System.out.print(model.getValueAt(table.getSelectedRow(), 0));
System.out.println();
closeConnection(o.toString());
// Delete row from window too.
((DefaultTableModel)table.getModel()).removeRow(table.getSelectedRow());
table.revalidate();
table = DisplayCSeqNos.createTable(items, "Disconnect", al);
frame.getContentPane().add(new JScrollPane(table));
frame.pack();
frame.show();
} // End Constructor.
public void closeConnection(String s){
/*1. Disconnect the current session*/
this.clientMgr.disconnectCall(s);
/*2. refresh the Disconnect window*/
this.refreshWindow();
public Vector displayCSeqNos(Hashtable callLegTable){
Enumeration eNum;
String str;
Vector v = new Vector();
eNum=callLegTable.keys();
while(eNum.hasMoreElements()){
str = (String) eNum.nextElement();
//System.out.println("Key : " + str + " Value : " + callLegTable.get(str));
v.addElement(str);
return v;
} // End of displayCSeqNos.
Maybe you are looking for
-
How do I transfer all updates to my ipad ?
In iTunes, I clicked on the Apps, and then Update all Apps. As I hadn't done this in a while, it went ahead and updated 100 apps or so. When it was done, it informed me I had no additional updates. Then I plugged in my iPad, and I expected to be a
-
Aren't melted magsafe cables waranty replaceable?
I have a melted cable and I have to bend it to make the thing work now and charge the macbook, but when I went to waranty, they said I cut it with scissors and after that it melted. What kind of explanation is that? The computer is still under warant
-
[Solved] Simple question
How do I edit my current rc.conf after installation? I'm new to arch and don't know a lot of console commands yet, and I recently found out I need to edit the modules array in rc.conf but I have no idea how. Last edited by dm29 (2009-01-13 00:23:54)
-
all of a sudden my iphone stopped charging and you can't hear the music through my ihome iH150 when I connect it to the dock, what can I do to fix the ihome? The ihome does turn on and I already checked for dock possible problems and I don't see anyt
-
Tpforward tpabort causing rollback to oracle database ?
Hello all, we have issue with xa transactions. We obtained tpabort / rollback as you can see from the trace. We are trying to send messges from queue using tpforward to databse using oci - through "ods" adapter. This issue is obtained sometimes, afte