Unix/Linux Go Back    


Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Removing characters form text file and replaicng

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-09-2013
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 14 June 2017, 7:09 AM EDT
Posts: 140
Thanks: 26
Thanked 1 Time in 1 Post
Removing characters form text file and replaicng

I currently have a text file which looks like this


Code:
2010.26 (0.0306746) @ 59,19

I want to remove all 22 characters up till the "59"

NOTE: REMOVE, not replace with (null)
NOTE2: The 59 CANNOT be taken as a number to consider in the script... it is not fixed. The only thing that is fixed is the 20 characters at the start till we reach the 59.

furthermore I want to replace the "," with a "+" sign.

Thanks in advance.

Last edited by pasc; 03-09-2013 at 08:56 AM..
Sponsored Links
    #2  
Old Unix and Linux 03-09-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 20 October 2017, 3:27 AM EDT
Location: San Jose, CA, USA
Posts: 10,544
Thanks: 551
Thanked 3,693 Times in 3,151 Posts
With the given input example, this works:

Code:
sed 's/.* //;s/,/+/' file

but I have no idea if this is representative of what you really want to do.

Are you trying to delete everything before a literal "59" or are you trying to delete everything up to and including the last space on a line?

Is there only one line in your input file?

Are you trying to change the contents of the file, or are you trying to extract and modify data in the file without changing the file itself?
Sponsored Links
    #3  
Old Unix and Linux 03-09-2013
pasc pasc is offline
Registered User
 
Join Date: May 2011
Last Activity: 14 June 2017, 7:09 AM EDT
Posts: 140
Thanks: 26
Thanked 1 Time in 1 Post
start beginning from the end of the file and delete every thing after the fifth character (59)
> maybe this can be achieved by reading the 5 last characters of the line and write it to the same text file ?

Ok, the replacing part will work like this:

Code:
set /p text= <textfile.txt    
set str=%text% 
echo.%str%  
set str=%str:text-to-replace=replacing-text%
ECHO %str% > textfile.txt

---------- Post updated at 11:40 AM ---------- Previous update was at 10:11 AM ----------

Is there a way to read the last - lets say 7 characters- from a line into a variable ?

Last edited by pasc; 03-09-2013 at 11:07 AM..
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
removing file with bad characters BeefStu Shell Programming and Scripting 4 09-13-2011 09:36 AM
Text file + image/form/overlay file to PDF 65bit UNIX for Dummies Questions & Answers 1 05-26-2011 11:54 AM
Removing ^M characters from a file mwrg Shell Programming and Scripting 10 11-17-2009 09:50 AM
removing unwanted characters from a file saravanan71184 Shell Programming and Scripting 4 08-20-2009 03:30 AM
Removing certain characters in a file bombcan Shell Programming and Scripting 2 04-25-2008 03:53 PM



All times are GMT -4. The time now is 06:45 AM.