Computing.Net > Forums > Unix > Unix/dos amending text

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Unix/dos amending text

Reply to Message Icon

Name: jackngill
Date: April 8, 2006 at 12:05:09 Pacific
OS: Windows/DOS
CPU/Ram: 384
Product: Acer
Comment:

Well this may start out a tad bit confusing but here goes:
Dossy bit - I have managed to condense the output details from mem.exe in batch to get a single line of text using:
MEM.EXE | FIND.exe /I "Total memory" >> C:\r1.txt which produces in r1.txt:-
Total<1space> memory<6Spaces>131,008K<7spaces>489K<3spaces>130,519K (all 1 line in r1.txt the <space> bit is just to indicate blank space separations)

I have heard of 2No utils which are used in UNIX but can be used in DOS (Batch) that can amend/remove text & numbers so that I am just left with say the first block of numbers without the comma's & the K's at the end of each block of numbers. The 2No programs are TR & SED, however I am unfamiliar with the syntax to remove Total memory, all the comma's & the K's from the first set of numbers then the remaining two blocks of numbers, comma's & K's also. Any one who is familiar with preferably TR, could they reply with the suitable syntax/code & squeeze/remove any blank spaces. The nearest stab i could make at it was, don't laugh!:
echo Totalmery | tr -d 'Totalmery' >> r1.txt then possibly to squeeze multiple charaters into one set numbers: ls -l | tr -s ' '
The removal of the 2 other blocks of numbers I haven't got a clue about?
I want to wind up with 131008 nothing else in r1.txt or possibly r2.txt.
Regards,
appreciably yours,
Dave



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: April 8, 2006 at 12:53:37 Pacific
Reply:

This can also be done with Perl. This perl command will do an inline edit of the Totalmery.

perl -pi -e 's/^\D+(\d+),(\d+).*/$1$2/' Totalmery

The sed command would be very similar, the key part is the regex (regular expression).

Using tr would not be the best choice, but if you plan on using it, you'll need to make several passes.


0

Response Number 2
Name: jackngill
Date: April 8, 2006 at 14:56:44 Pacific
Reply:

Hi FishMonger,

Thanks for the reply I don't have a clue about perl programming or compiling sorry! If I was to use TR in several passes what would the code be as TR is a smaller program?
If not what would the SED code be please. I was hoping to use this generally on different PC's with different amounts of RAM/MEM installed that would involve %Variables% way 2 complicated for me!
I have noticed that the above code presumeably wouldn't remove the other 2No blocks of numbers yes?

Regards,
Dave


0
Reply to Message Icon

Related Posts

See More


chmod operation not permi... Name of working directory



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix/dos amending text

Printing Unix text properly (URGENT) www.computing.net/answers/unix/printing-unix-text-properly-urgent/3085.html

NEED TO PRINT HTML IN UNIX! HELP! www.computing.net/answers/unix/need-to-print-html-in-unix-help/2834.html

sql query in unix scritp www.computing.net/answers/unix/sql-query-in-unix-scritp/6420.html