Question about Operating Systems

1 Answer

String Manipulation in Batch Script

Hi

I am trying to extract substring using tokens but i couldn't extract the second token in the string

Here is an example what i am trying to do
---------------------------------------------------
i have a list of files in a folder, the filenames are something like file_somenamev1.3.zip
i need to extract the first 4 characters from the second token ('some' from 'somenamev1.3.zip')

Can anyone please suggest how to do this. i have copied my code below. which isn't working. i couldn't retrieve the value into a variable

Code:


FOR /F %%x in ('dir /b D:\temp\*.zip') do (
FOR /F "TOKENS=1,2 DELIMS=_ " %%C IN ('echo %%x') do (
echo C:%%C D:%%D
set str1 = %%C
set str2 = %%D
REM The value in str1 & str2 is always null, couldn't initialize the values of %%C & %%D to str1 & str2
echo str1 %str1%
echo str2 %str2%
)
)



thanks for your help
Sri

Posted by on

1 Answer

  • Level 3:

    An expert who has achieved level 3 by getting 1000 points

    All-Star:

    An expert that got 10 achievements.

    MVP:

    An expert that got 5 achievements.

    Brigadier General:

    An expert that has over 10,000 points.

  • Master
  • 10,406 Answers

/* REXX is better than Batch Scripting -- see http://www.REXXLA.org */
filename = 'file_somenamev1.3.zip'
char = '_'
parse var filename part1 (char) part2
first4 = left(part2,4)
say 'First 4 characters are:' first4
exit

Posted on Dec 03, 2009

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

How can I slove the error ERR:DATE TYPE when I try to run a program I have written?


You're attempting an operation that is not valid for a particular data type, like taking the square root of a string or extracting the second character of a floating-point number.
First, localize the error. Find the line number or location of the error, then narrow it down to the operation. Then examine the value(s) being used in that operation and their types. Make sure the operation is valid for that type(s).

Aug 01, 2013 | Operating Systems

2 Answers

Http login yahoo com config reset cookies token Problem


Hi inna!
Delete the cookies and retry
It'll fix it.

Please mention which internet browser are you using if you don't know how to delete the cookies.
Firefox:
Go to Tools>Options (a new window will open)
There click on Privacy option and then click on REMOVE INDIVIDUAL COOKIE (its in the middle of the screen)
Then search for the yahoo.com. click on it and then click remove cookie button.
Internet Explorer 8!
G to Tools> Internet Option> then under the Browsing History panel click on DELETE Button.In the new window only check the box behind the COOKIES and then click on DELETE button

Thanks

Jun 07, 2011 | Operating Systems

1 Answer

How can i change text of Start Button?


You Need to Modify "Explorer.exe File" To make the changes you need to locate and edit the file "explorer.exe" it's located at C:Windows. The file "Explorer.exe" is a binary file, so you will need special editor (Resource Hacker) will do. Resource Hacker is a good freeware utility to view, modify, rename, add, delete and extract resources in 32bit Windows executables and resource files. First Backup "explorer.exe" located at C:\Windows\explorer. You can place it in a special folder or save it to disk. You can also copy and change the file name to "explorerB.exe" (the B is for backup), then you can edit "explorer.exe".

2. Resource Hacker: In Resource Hacker the category will be using is String Table. You need to expand it by clicking on the plus sigh, then navigate down and expand string 37 followed by 1033, (For Classic Layout use number 38). On the right hand pane look for item 578 it show the word "start" this is what we are going to modify.

3. Edit start: To edit the word "start' you just double click on start so that it's highlighted, don't highlight the quotation marks on the sides of start, "start" NOT "start". The new text go's in between the quotation marks, like this "new" remember don't delete the quotation marks. So that it looks like this "new" replace new with your text. This is the old start text "start" delete start text "", inter your text "new" easy right!

4. Compile Script button: Now that you have changed the start text you need to click on the Compile Script button. After you have clicked on the Compile Script button you need to use the Save As command on the File Menu to save the altered file and give it a name. A good file name "explorernew.exe" or make your own. Don't use the Save command use the Save As commaned! Save the newly named file to the C:\Windows.

5. Modify the Registry: Now it's time to modify the registry so that your modified explorer.exe file that you created will be recognized when the user logs on your system. Go to the Start button click on it, then go to Run click on it, type regedit in the Open: field. Now Navigate download the list to "HKEY_LOCAL_MACHINE" click on the plus, to SOFTWARE, to Microsoft, to windows NT, to CurrentVersion, to Winlogon. The full string: HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\ Windows NT\ CurrentVersion\ Winlogon
Look on the right pane for Shell, double click on Shell entry to open the Edit String dialog box. In the Value date: line enter the name that your used to save the modified explorer.exe file. click on OK.
Now close Registry Editor and exit Windows or log off your system, and then log back on. Now if the computer gods are happy and all went as planned you should see the new Start button with your cool text on it. Remember the force is with you!

Jul 08, 2009 | Operating Systems

2 Answers

For the code snippet output of this if code produce if aNumber 3


There is a bug in this code. The correct code is:-


if (aNumber >= 0)
if (aNumber == 0)
System.out.println(''first string'');
else
System.out.println(''second string'');
else
System.out.println(''third string'');

Mar 21, 2009 | Operating Systems

1 Answer

Please explain the working of this code


It's a Java http server (webserver) that serves random "prices" if they match a search string.

Well here is an explaination:

private static String[] symbols = {"DELL", "INTC", "MSFT", "ORCL", "SUNW"};
These are search strings

private static Random rnd = new Random();
This generates a random number

private static Charset cs = Charset.forName("UTF-8");
This is the charset that the http server uses

ServerSocketChannel server = ServerSocketChannel.open();
Create a new server

server.socket().bind(new InetSocketAddress(8055));
Bind the http server to port 8055

The rest is handling the request and processing it

But here:
if(Arrays.binarySearch(symbols, symbol) >= 0)
response = "Price is " + (1000 + rnd.nextInt(9000)) / 100.0;
else
response = "Price not available";
channel.write(cs.encode("HTTP/1.0 200 OK "));
channel.write(cs.encode("Content-type: text/plain "));
channel.write(cs.encode(response));
channel.close();
}
It sees if the string input matchs: DELL INTC MSFT ORCL SUNW.

(private static String[] symbols = {"DELL", "INTC", "MSFT", "ORCL", "SUNW"};)
If so, it gives a price based on a random number.
(
response = "Price is " + (1000 + rnd.nextInt(9000)) / 100.0;)
Or else
It says "price not available"
then it gives a html header to end the error message.

Hope I helped you :)
Gook luck

Nov 26, 2008 | Operating Systems

1 Answer

An unhandled exception has occured .......


An attempt was made in a program or script to use an object before creating the object. For example:

dim SomeObject as Object
SomeObject.attribute = "string value"

will generate thie error message because the SomeObject that is being referred to has not been created. For this, we need the New keyword:

dim SomeObject as New SomeObject
SomeObject.attribute = "string value"

will run without errors

Nov 19, 2008 | Microsoft Windows XP Home Edition

1 Answer

Java program


I would use Perl, easier. Maybe even use POP and PUSH on ARGV to pull the forst argument off as directory and last as extension treating all the other entries as search criteria.

#!/usr/bin/perl # # Date: 13/02/2008 # # Author: Adrian Pavone # # This script takes a specified directory with any number of keywords as arguments,
# and then searches all sub directories, for those keywords. It only # returns a match if it finds all keywords in the same file name. # use File::Find; $dir =$ARGV[0];
; @searchTerms = @ARGV; find ( sub { for my $term (@searchTerms) { return unless $_ =~ /\Q$term/i; } print "$File::Find::name\n"; }, $dir);

Sep 18, 2008 | Operating Systems

2 Answers

Pattern matching


Nice try!

It's been almost 15 months since you asked your question.

If nobody has helped you with your "homework" assignment,
you probably scored a "zero" on your computer-programming course,
and probably no longer need an answer to your problem.

Sep 12, 2008 | Operating Systems

Not finding what you are looking for?
Operating Systems Logo

Related Topics:

795 people viewed this question

Ask a Question

Usually answered in minutes!

Top Operating Systems Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18298 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Prashant  Sharma
Prashant Sharma

Level 3 Expert

1127 Answers

Are you an Operating System Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...