All Questions

Filter by
Sorted by
Tagged with
0
votes
4answers
45 views

Find and replace after a string after a specific character

I have the following lines in my input file and I would like to replace all the text after "=" sign with a new string, say "good". Again, I would like to do this only for certain strings in the line....
2
votes
3answers
44 views

Loop over numbered files and append on every line of file the content of another file with the same number

I have a lot of numbered *.csv files with different numbers of lines and just as many *.txt files. I want to append on every line of file 1.csv the content of file 1.txt, on every line of file 2.csv ...
1
vote
2answers
64 views

How to Replace 3rd column (until a specific char) in a file from another file

I have two files: bor.mol2 and bor.com In bor.mol2, there are X,Y,Z coordinates of atoms between @<TRIPOS>ATOM and @<TRIPOS>BOND keywords in this file 3th, 4th and 5th columns are ...
2
votes
4answers
83 views

Parse a csv file, replace separator, ignoring the content of fields between “ ”

I have a file with ; separators ; my application parses the data, based on those separators. String fields are between "" and in columns, I might have the separator as text. I would like to replace ...
7
votes
1answer
304 views

Is it possible to replace duplicates of a character with one character using tr

I'm trying to take all occurrences of # and if they are consecutive replace them with just one #. e.g. ab ### cde fghi## jklm would become: ab # cde, fghi# jklm My initial goal was to replace ...
2
votes
2answers
271 views

Bash replace string at multiple places in a file from command line

I have a file with the below content. I want to replace chrome with chromeBackup but not in all places. Name=chrome XXXXXXXXXXX Run=bin -app "chrome/chrome.sh" XXXXXXXXXXX Vol.apps/chrome=chrome ...
0
votes
2answers
38 views

How do I use different replacement texts for a pattern found multiple times [duplicate]

sample log file: apple AAA rose banana AAA tulip orange AAA marigold replacement-text file: 111 222 333 Expected output: apple 111 rose banana 222 tulip orange 333 marigold
2
votes
3answers
75 views

Conditionally replace lines of file1 with the corresponding lines of file2

For example, I have two files: file1: 1 4 X 5 X 7 file2: 2 3 5 X X 1 I want to replace X-lines of file1 with whatever is in file2 on the corresponding line: result: 1 4 5 5 X 7 I prefer the ...
-2
votes
1answer
40 views

Replace string in one file with contents of another file when match column

I have two files like: file 1 : a stringori to replace, this stringori comme again other stringori2 to replace, stringori2 commes again ... file 2: stringori newstring stringori2 newstring2 ... ...
0
votes
3answers
73 views

Recursively find and replace contents of one file using a key from another file

I need to use one file as an input to find and replace in another file. The following command does so, but only for the first column for each line. I need this to happen for every column. awk -F',' '...
1
vote
1answer
69 views

preg_replace for replacing comment text in a file

In a file, I want to replace COMMENT AS `<some_comment>` with COMMENT '<some_comment>' That is, replace COMMENT AS with just COMMENT, and replace the backticks around the following ...
1
vote
2answers
339 views

Bash replace string with command

I have a command (logcat) which outputs a long log like this: 07-27 09:26:22.416 17574 17886 D SurfaceControl: Excessive delay in setPowerMode() 07-27 09:26:22.421 17574 17599 I PowerManagerService: ...
1
vote
4answers
114 views

Replace text with values

I have two files that need to be merged into one. File 1 example: gene_1 578 gene_2 565 gene_3 3 gene_4 77 gene_5 8 gene_6 0 gene_7 45 gene_8 67 gene_9 0 gene_10 65 File2 example: COG0430 ...
0
votes
2answers
113 views

text file search yyyy/mm/dd and replace with yyyy-mm-dd

I have a file with many tags in the form of yyyy/mm/dd as in the line below and want to replace the / with - to give yyyy-mm-dd at all instances in the one file. e.g. from this: <tag k='start_date'...
1
vote
2answers
74 views

Find and Replace Duplicates

I have a file with concatenated emails in it that looks like the following: id emails 1 jeff@email.com 2 larry@email.com 3 jprice@email.com,jeff@email.com,jeff@stacko.com Each row only has ...
-1
votes
1answer
80 views

find and replace [closed]

I have 2 files. The first column (separated by ",") in file1.txt is equal in file2.txt. I want to compare both files and replace for second column in the file1.txt in file2.txt file1.txt ABC-aBc-...
3
votes
7answers
593 views

Remove comma outside quotes

I have a input file delimited with commas (,). There are some fields enclosed in double quotes that are having a comma in them. Here is the sample row 123,"ABC, DEV 23",345,534.202,NAME I need to ...
1
vote
0answers
38 views

Replacing variables in files with value from another file [duplicate]

I have an input file which contains variable and their values. $ cat input.txt var1=SomethingNew var2=SecondPrhase classpath=/this/is/some/path I have another directory in which there are multiple ...
4
votes
3answers
836 views

Ignore part of the string with sed

so, I have files with text formatted like this: untranslatedString : "translated string", and I need to replace characters in "translated string" part with their Cyrillic representation. I use ...
1
vote
4answers
101 views

Script to replace last slash in the mount point

I'm trying to do a script to delete the last "/" in the mount point inside of the fstab. I create this shell script, but, I'm not happy with the result. I wonder if anyone knows how to replace with ...
0
votes
3answers
596 views

How to replace last occurence of a character?

I have a file composed by lines like these ones: 199240050;0180209199240050;0 199240241;0180209199240241;0 199240207;0180209199240207;0 199240400;0180209199240400;0 I should replace last number ...
0
votes
1answer
138 views

Replace a value in URL

I'm new to Linux world and need some help. I have two files : A token.txt file with a string something like this: xd2111Vf124FfmrfJ22fag And a playlist.m3u file with the following: EXTM3U EXTINF:-1,...
0
votes
3answers
914 views

Replace forward slash “/” in a file

I'm using vi editor, I have a data like this in a file. 05/08/2017,U,01,116326001 05/08/2017,U,01,116226001 05/08/2017,U,01,116726323 05/08/2017,U,01,116236001 I want to replace the date(1st ...
0
votes
1answer
42 views

How do I extract a portion of an SQL statement for the purposes of searching and replacing?

I'm using bash shell attempting to do a search and replace. I have a file of lines that look like ... INSERT INTO currency (name, code, symbol) VALUES ('Baht', 'THB', '฿'); ... and I want to ...
2
votes
3answers
131 views

Replace string 1 only when string 2, 3, or 4 present

Basically I am an oracle dba. We have a task to switch-over from primary db to standby db and we need tns entries (host-name) to be modified from sape-scan to sapi-scan in the tnsnames.ora file ...
1
vote
2answers
960 views

multiple replacements on single line with sed

I would like to scan a whole file tree and do two replacements any line with two matches, i.e.: printf("Hello WORLD! %s, %d\n",bcm_errstr(rv),var); dprintf("kjhgjkhfkhgfjgd %s\n",bcm_errstr(rv)); ...
-2
votes
1answer
31 views

Replacing rows from one file with rows from other file [closed]

I am thinking how can I replace a portion of a file -- let's say lines from m to n with lines from other file and do this in an nice manner. I however don't want to ...
0
votes
1answer
207 views

Replacing text between two specific strings

I have large number of files that have an deprecated css value "hspace" and I want to change it with other css style value. Here is an example: we have: hspace='5' and we want to change with: style=...
-1
votes
2answers
49 views

Replace characters in a hapmap data set

I am thinking to use a bash code to solve the following issue in my data. Considering the bellow data set in hapmap format in which I need to replace some characters (letters in this case) based on ...
2
votes
1answer
539 views

How do I replace tokens from one file with data from another?

I'm using Amazon Linux with bash shell. I have a file with comma delimited data, where each row looks like this 2049,576804C7DF554416A9EA25B2A5A81514,X, Then I have a second file, with comma ...
0
votes
1answer
507 views

Replacing one column with another column in csv files [duplicate]

I have a file1 with the following: 1,joe,jim,bob,sally,mark,sue,etc,etc 2,julie,barbra,joe,jim,bob,sally,mark,sue,etc,etc 1,clarie,mike,joe,jim,bob,sally,,etc,etc 2,matt,alivia,joe,jim,bob,mark,sue,...
8
votes
6answers
22k views

Replace all values in one column to 1

I have multiple text files containing 12 lines and 3 columns. Example: 2 6 0.74 42 6 0.58 80 6 0 112 6 0.24 132 6 1 216 6 0.7 342 6 ...
2
votes
1answer
2k views

Remove white spaces before certain characters

I am trying to remove spaces from text like: Ala ma kota ,psa i kanarka , chyba . . . in order to get Ala ma kota,psa i kanarka, chyba... I was trying with sed command: echo $'Ala ma kota ,psa i ...
0
votes
2answers
38 views

Replacing string with other string

In line((s) that originate from csv file) 14/Feb/2016:15:21:33-0500]http://map1.link.de/mk what is the easiest part to replace/delete&add ]http://map1.link.de/ with , having in mind that ...
0
votes
1answer
564 views

sed replace first occurrence of “space-tab” pattern

I have some troubles removing the string between the first space \s and the first tab \t of a text file (the tab should be kept): sample input: col1_frame1 unimportant a b c expected output ...
0
votes
1answer
3k views

Using regexp_replace to replace single quotes around string but not within words e.g. can't

I'm using the below code from a bash script to replace single quotes from my title column in a postgres database with spaces. psql -U postgres -d my_database -c "UPDATE my_table SET title = ...
1
vote
1answer
488 views

Replacing mysql settings with sed

I am creating a backup web server but I want the backup server to only have one root user. So after moving all the databases I need to replace all the mysqli_connect(...) lines in db.txt. I have ...
3
votes
2answers
196 views

How to replace a piece of text only if it doesn't appear elsewhere in the file?

Suppose I have some text like this (output of objdump -d): 0: 0f a2 cpuid 2: a9 01 00 00 00 test eax,0x1 7: 74 01 je a <myFunc+...
1
vote
1answer
89 views

How to replace word in specific column if it does not match an expression?

I have the following file: chr1 157784 157887 U6 0 - chr1 564813 564881 miRNA 0 + chr1 564879 564950 tRNA 0 - chr1 564952 565019 tRNA 0 + chr1 566062 566129 ...
1
vote
4answers
214 views

How can I replace a character in all the .php files inside a folder on OS X?

I need to replace the following characters: ă with a â with a î with i ș with s ț with t The replacement must be case sensitive. For example if a letter is upper-case then it must be replaced ...
4
votes
3answers
543 views

Remove long string from files

Files on my server have been corrupted. I want to remove a 13000 character string from all PHP files containing it. The string looks like: ?php if(!isset($GLOBALS["\x61\156\x75\156\x61"])) { $ua=...
4
votes
3answers
363 views

Convert genotypes to 0/1

I have a file that looks like: 1 rs6687776 1020428 T C T C T C C C T C C C T C The 4th and 5th column are the two different possible alleles at that ...
0
votes
1answer
115 views

How to replace \1\ with new line

I have a record like: "evSchema"\1\"UAT" "evSN"\1\"uadb" "evDirsep"\1\"/" "evRootPath"\1\"/work_area/APP_UAT/" "evSchema"\1\"RMS13" "evUser"\1\"STAGE" I want to replace \1\ with new line. I tried ...
2
votes
3answers
6k views

How to replace value for a given condition in specific column of file

I have file separetd by pipe | and I want that when column 6 contain letter I print 0758000 in column 7 and when the column 6 contain letter A print 0800000 in column 7, I can not find how to do it!!! ...
1
vote
1answer
6k views

How to replace the content of specific column with awk? Tab Delimited File

Here's a similar question but I ran into a problem that was not addressed in the question. How to replace the content of a specific column with awk? I want to do something similar, however my file is ...
4
votes
2answers
708 views

Bash - Convert escape character colored text to BBCode

I want to convert a terminal escape-character colored text file to BBCode colored text. For this i've created an Android logfile with logcat -Cd > /sdcard/logcat.txt. The -C switch adds the color ...
2
votes
2answers
114 views

Search and Replace question

I need to find all occurrences of AAsomeArbitraryStringBB and replace it with CCsomeArbitraryStringDD. So AAHelloBB Text AAByeByeBB becomes CCHelloDD Text CCByeByeDD. It's important to note that ...
1
vote
2answers
99 views

find and replace a value in a line of text

I have a text file which contain only 1 line of text 1314:Battery:1.90:50:30 I'm trying to figure out if is there anyway to do a grep and sed to change the value 50 and 30 to the following 1314:...
1
vote
1answer
99 views

How to replace a symbol in sed only if it occurs before a letter?

In my documents, I have lots of occurences like these: [["A [["b [["8 [["c [["F [["1... What I need to do is to replace double brackets with single brackets, but only if there is a letter after a [["...
0
votes
2answers
4k views

Match a whole word (IP address) using `sed`

I have the following line style in a file: 1.2.3.4 1.2.3.4a 1.2.3.45 iaa1.2.3.4ad 11.2.3.4a a1.2.3.4 1.2.3.4> <1.2.3.4> <"1.2.3.4"> 1.2.3.4 hostname I want to replace all the ip '1.2....