Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Find and replace a string in a text file Post 302974453 by forevertl on Monday 30th of May 2016 09:53:45 PM
Old 05-30-2016
Find and replace a string in a text file

Dear all,

I want to find all the "," in my text file and then replace the commas to a tab. I found a script online but I don't know how to modify the script for my case. Any one can help? Thank you.
@echo off &setlocal
Code:
set "search=%1"
set "replace=%2"
set "textfile=Input.txt"
set "newfile=Output.txt"
(for /f "delims=" %%i in (%textfile%) do (
    set "line=%%i"
    setlocal enabledelayedexpansion
    set "line=!line:%search%=%replace%!"
    echo(!line!
    endlocal
))>"%newfile%"
del %textfile%
rename %newfile%  %textfile%

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how can search a String in one text file and replace the whole line in another file

i am very new to UNIX plz help me in this scenario i have two text files as below file1.txt name=Rajakumar. Discipline=Electronics and communication. Designation=software Engineer. file2.txt name=Kannan. Discipline=Mechanical. Designation=CADD Design Engineer. ... (6 Replies)
Discussion started by: kkraja
6 Replies

2. Shell Programming and Scripting

Find and replace string from file which contains variable and path - SH

e.g. /home/$USER/.config replace it with "" (empty) Is this possible? I think you should play a bit with sharps ## and sed:b: (2 Replies)
Discussion started by: hakermania
2 Replies

3. Shell Programming and Scripting

Find text containing paths and replace with a string in all the python files

I have 100+ python files in a single directory. I need to replace a specific path occurrence with a variable name. Following are the find and the replace strings: Findstring--"projects\\Debugger\\debugger_dp8051_01\\debugger_dp8051_01.cywrk" Replacestring--self.projpath I tried... (5 Replies)
Discussion started by: noorsam
5 Replies

4. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies

5. Shell Programming and Scripting

find from file and replace with specific text

Dear All, I do not have any knowledge of scripting. I want to replace specific lines of a text file with a specific text. Like I have one file which is "original file" and one file "changes file" which has list of lines which I want to replace in original file with a specific string. I want the... (5 Replies)
Discussion started by: libras
5 Replies

6. UNIX for Advanced & Expert Users

Find and replace the line in text file

I have two files a.txt b.txt I want to find a line in a.txt and replace by another line from b.txt a.txt asfsdfsfsfdfsf asfwererfgdgf wrerwetretfdg b.txt werdfgdfgf werergfdgd sfdfgfgfgfgg i want to replace the 1st line of a.txt by 1st line of b.txt i want out put as (5 Replies)
Discussion started by: rammm
5 Replies

7. Shell Programming and Scripting

find string and replace with string in other file

Dear all, I need your help, I have file like this: file1:23456 01910964830098775635 34567 01942809546554654323 67589 26546854368698023653 09778 58716868568576876878 08675 86178546154065406546 08573 54165843543054354305 . .file2: 23456 25 34567 26 67589 27 (2 Replies)
Discussion started by: attila
2 Replies

8. Shell Programming and Scripting

Find and replace string based on entries on another file

I have a file1 with different with multiple fields and records File2 has 2 fields. I want to find and replace strings in file1 based on file2 values (I Want an exact match i.e. for example: when searching for DT:3, Substr of DT:34 should not be matched) File2: DT:3 foo_err DT:34 bar_frr... (8 Replies)
Discussion started by: aydj
8 Replies

9. Shell Programming and Scripting

Perl script to read string from file#1 and find/replace in file#2

Hello Forum. I have a file called abc.sed with the following commands; s/1/one/g s/2/two/g ... I also have a second file called abc.dat and would like to substitute all occurrences of "1 with one", "2 with two", etc and create a new file called abc_new.dat sed -f abc.sed abc.dat >... (10 Replies)
Discussion started by: pchang
10 Replies

10. UNIX for Beginners Questions & Answers

Find replace text in xml file on the fly

Dear Unix guru, I have a .XML file which is being used to load data to oracle. This file comes on unix box and one of the tag in xml is oracle key word. I want to find that tag and replace with new tag on the fly For example I will get one of the tag in xml is as below <from>Test Test... (12 Replies)
Discussion started by: guddu_12
12 Replies
ppmtoxpm(1)                                                   General Commands Manual                                                  ppmtoxpm(1)

NAME
ppmtoxpm - convert a portable pixmap into an X11 pixmap SYNOPSIS
ppmtoxpm [-name=xpmname] [-rgb=rgb-textfile] [-alphamask=pgmfile] [ppmfile] Minimum unique abbrevations are acceptable. DESCRIPTION
Reads a portable pixmap as input. Produces X11 pixmap (version 3) as output which can be loaded directly by the XPM library. For example, to convert the file "dot" (found in /usr/include/X11/bitmaps), from xbm to xpm one could specify xbmtopbm dot | ppmtoxpm -name dot or, with a rgb text file (in the local directory) xbmtopbm dot | ppmtoxpm -name dot -rgb rgb.txt OPTIONS
-name=xpmname The -name option allows you to specify the prefix string which is printed in the resulting XPM output. If not specified, will default to the filename (without extension) of the <ppmfile> argument. If you do not specify -name or ppmfile, (i.e. your input is from Standad Input), the prefix string defaults to the string noname. rgb=rgb-textfile The -rgb option allows you to specify an X11 rgb text file for the lookup of color name mnemonics. This rgb text file is typically the /usr/lib/X11/rgb.txt of the MIT X11 distribution, but any file using the same format may be used. When specified and a RGB value from the ppm input matches a RGB value from the <rgb-textfile>, then the corresponding color name mnemonic is printed in the XPM's colormap. If you don't specify -rgb or if the RGB values don't match, then ppmtoxpm produces the color specifications in the #RGB, #RRGGBB, #RRRGGGBBB, or #RRRRGGGGBBBB hexadecimal format. -alphamask=pgmfile This option names a PGM file to use as an alpha (transparency) mask. The file must contain an image the same dimensions as the input image. ppmtoxpm marks as transparent any pixel whose position in the alpha mask image is at most half white. If you don't specify -alphamask, ppmtoxpm makes all pixels in the output opaque. ppmcolormask is one way to generate an alpha mask file. You might also generate it by extracting transparency information from an XPM file with the -alphaout option to xpmtoppm. There are similar options on other Netpbm converters that convert from formats that include transparency information too. LIMITATIONS
An option to match the closest (rather than exact) color name mnemonic from the rgb text would be a desirable enhancement. Truncation of the least significant bits of a RGB value may result in nonexact matches when performing color name mnemonic lookups. SEE ALSO
ppmcolormask(1), xpmtoppm(1), ppm(5) XPM Manual by Arnaud Le Hors lehors@mirsa.inria.fr AUTHOR
Copyright (C) 1990 by Mark W. Snitily. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, pro- vided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in sup- porting documentation. This software is provided "as is" without express or implied warranty. This tool was developed for Schlumberger Technologies, ATE Division, and with their permission is being made available to the public with the above copyright notice and permission notice. Upgraded to XPM2 by Paul Breslaw, Mecasoft SA, Zurich, Switzerland (paul@mecazh.uu.ch) Thu Nov 8 16:01:17 1990 Upgraded to XPM version 3 by Arnaud Le Hors (lehors@mirsa.inria.fr) Tue Apr 9 1991 Tue Apr 9 1991 ppmtoxpm(1)
All times are GMT -4. The time now is 12:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy