1
vote
1answer
102 views

replace a pattern found with a number plus 1 on the same line

I have a file where each line contains a keyword (HELLO) and one or more numerical fields designated A1, A2, etc. The value in the numerical field is enclosed in brackets after the field name and is ...
1
vote
3answers
70 views

Pattern Matching and Delete the whole line

I want to delete all the Lines of File 1, if Column1 of File1 matches exactly with Column 1 File2. File 1: r001:21:10 21 AAAAAATTTGC * = XM:21 r002:21:10 21 YAAAATTTGC * ...
4
votes
2answers
153 views

Replace string with sequential index

Can someone suggest an elegant way to accomplish this? Input: test instant () test instant () ... test instant () //total 1000 lines output should be: test instant1 () test ...
-2
votes
3answers
71 views

Deleting Lines, which match a particular Identifier from another file

I have 2 files. File 1, has an identifier (eg. D7MHBF:11:1449:1988) and every new entry starts with @. It has few more fields, which are not important in our analysis. File 2 consists of a column of ...
6
votes
1answer
166 views

How can I replace a string in a file(s)?

Replacing strings in files based on certain search criteria is a very common task. How can I replace string foo with bar in all files in the current directory? do the same recursively for sub ...
2
votes
1answer
32 views

Count and merge consecutive patterns

I'm searching for a short snippet to find, count and merge consecutive duplicates using standard tools or a common scripting language. Say our input is: 1 2 2 2 7 22 a b b c c c c c d dd 2 2 c c ...
3
votes
2answers
375 views

How to convert a .txt subtitle file to .srt format?

I have a subtitle file, it looks like this: 00:00:44:" Myślę, więc jestem".|Kartezjusz, 1596-1650 00:01:01:Trzynaste Pietro 00:01:06:Podobno niewiedza uszczęśliwia. 00:01:10:Po raz pierwszy w ...
1
vote
1answer
134 views

how to subtract a constant value from a data file?

I want to subtract a constant number from my data to get new data file. For example, I want to subtract 10 from my data. data.txt Id a b c d e 1 1 2 3 4 5 2 2 3 4 5 6 ...
1
vote
3answers
140 views

How to calculate the sum of the data that have the same ID in the first column?

I want to sum the values of the rows of my data that have the same ID in the first column. My data looks like data.txt Id a b c d e 1 1 2 3 4 5 1 2 3 4 5 ...
0
votes
2answers
72 views

How to Lookup the values of an index values from a big data file?

I have a data file (data_array.txt in the example) and index file, index.txt, at which I want to extract the data from the data file that have the same ID in the index file and store in to a new file, ...
4
votes
5answers
1k views

extract the 4th column from a csv file using unix command

I have a csv file formatted as below. "col1","col2","col3","col4" "1","text1","<p>big html text</p> ","4th column" "2","text2","<p>big2 html2 text2</p> ...
4
votes
4answers
121 views

Howto find and move a text line inside a file?

I need to change a text line position inside a file; from one line position to another one, underneath a defined text. For example, I have the following text block (on /etc/pam.d/system-auth file) ...
1
vote
1answer
100 views

Parsing the headers of sequence file

I have a multiple sequence file as >abc|d017961 sequence1...... >cdf|rhtdm9 sequence2...... >ijm|smthr12 sequence3...... >abc|d011wejr sequence4...... >stg|eethwe77 sequence5...... ...
1
vote
3answers
1k views

How to convert from one date format to other format?

I have one problem with my date format. I want to change from one format to the other and vice versa. My date formats are Format 1 YYYY-MM-DD Format 2 MM/DD/YYYY I want to change format 1 to ...
1
vote
1answer
52 views

how to clean free row/column spaces after the row of your data

I have a problem in cleaning my file where there are unnecessary free spaces below my last data row. This is created when I am copying and pasting my data from excel to text. I want my text file to ...
1
vote
1answer
69 views

How do I modify this Perl solution so that it will substitute embedded double quotes with single quotes?

Previously in this question: "string having doublequotes in between apart from the enclosing quotes" @BernieReiter asked a follow-up question where he wanted to take CSV entries such as the following: ...
2
votes
6answers
1k views

Repeat each line multiple times

Would like to have each line in a file repeated a fixed number of times. e.g. have each line repeated four times: a b c becomes: a a a a b b b b c c c c I've done some searching, and there are ...
2
votes
3answers
474 views

I want to find duplicates in a file and add a character to the end of the line on the 1st match

I am trying to find duplicates in a file and once a match is found mark the 1st match with a character or word on the end of the line. eg my file (test.html) contains the following entries host= ...
3
votes
3answers
137 views

sed + how to remove character/s that start or ended on each number

How do I remove the . character(s) that start in the beginning of each number or end on each number? Remark – perl one liner also good alternative for sed. Example input: .23.12.44.5. .233.3.3.3 ...
0
votes
1answer
91 views

read line by line and take a string in line and assign that string to the subsequent line using perl [duplicate]

Data file is fixed length file, and I want to read file line by line and take a string from the current line, and then append that string to the subsequent line and write into another file. For ...
-4
votes
1answer
109 views

How to transform two delimited ASCII files

These are 2 common delimited, text file transformation problems I'd like to find scripts to do (I dont know if awk or perl is best for these tasks). csh is the default shell on my Solaris10 unix ...
2
votes
5answers
2k views

How can I split a text file into multiple text files using Perl?

I have a file ABC_TabDelim.txt that contains the following: 00:00:00:00 00:00:05:00 01SC_001.jpg 00:00:14:29 00:00:19:29 01SC_002.jpg 00:01:07:20 00:01:12:20 01SC_003.jpg 00:00:00:00 00:00:03:25 ...
5
votes
2answers
1k views

Replacing missing value blank space with zero

I have input.txt tab-delimited text file around 30K lines, I would like to check each row (s1..s30K lines) for missing value (i.e blank space) and fill the missing value with zero value.See out.txt ...
2
votes
3answers
3k views

Extracting column from comma separated text

I have a long comma-separated delimited file with 20K lines. Here's a sample: "","id","number1","number2","number3","number4","number5","number6","number7" ...
0
votes
1answer
93 views

How to get rows between lines?

I have a perl oneliner: echo -e 'sla\ndfjAAAAk\nsaljdfla\nsjdfBBBBsadf\njasdf' | perl -E 'my $_ = do { local $/; <> }; say join qq!\n!, m!\QAAAA\E\K(.*?)(?=\QBBBB\E)!gs' k saljdfla sjdf it ...
4
votes
6answers
314 views

What is the easiest way to check if column A and B values goes both ways with AWK? [closed]

What is the easiest way to check if column A and B values goes both ways? Output to check: Mike John John Mike Pamela Barbara Barbara Pamela Mike Paul Roger Paul Desired output Mike <-> ...
4
votes
2answers
126 views

Column mismatch and substituting

input.txt (tab-delimted) TTTTOTTT00000000008 RTTTT899 5.00E-28 TTTTOTTT00000000046 RTTTWRR 3.00E-31 TTTTOTTT00000000051 2.00E-11 TTTTOTTT00000000051 7.00E-12 TTTTOTTT00000000054 ...
2
votes
1answer
214 views

text processing-perl

I am a biologist. I would like help of computer experts to help in text file editing. Here is what the input file looks like: ##dsfsd2 ##sdf-sdf sasg 5.6.3 gi34_ex Gen CDS 161 317 . ...
2
votes
2answers
1k views

How to do a regex search in a UTF-16LE file while in a UTF-8 locale?

EDIT: Due to a comment Warren Young made, it made me realize that I was not clear on one quite relevant point. My search string is already in UTF-16LE order (not in Unicode Codepoint order, which is ...
8
votes
6answers
1k views

Delete lines beginning with #

How do I delete lines beginning with a #, given that there can be whitespace on the left and right of the #? # Master socket provides access to userdb information. It's typically
2
votes
1answer
439 views

How to insert a first column to many files + how to convert unix time to normal time

There are many-many files in a directory that has e.x.: the following content: INPUT: root 1324711901 sshd 1272725792 And I'm searching for a solution how to convert the content of the ...
4
votes
4answers
854 views

How can I remove a specific string from a file only if there are other lines in the file?

How can I remove a specific string from a file ONLY if there are other lines in the file? For example, don't touch this file: cat file.txt ASDF but remove "ASDF" from this file: cat file.txt ASDF ...
1
vote
1answer
469 views

How to convert <a href=“http://xy.com”>XY</a> to [http://xy.com XY]?

Just for editing Wiki's.. So i have this input [from a larget text]: TEXT TEXT BLA-BLA RANDOMSTRINGS BLA-BLA TEXT TEXT BLA-BLA RANDOMSTRINGS BLA-BLA TEXT TEXT <a ...
3
votes
4answers
1k views

Replacing text from a list of replacements. Added complication: backslashes

I have a file A that contains pairs of strings, one per line: \old1 \new1 \old2 \new2 ..... I would like to iterate over file A, and for each line perform the replacement (e.g. "\old1 -> \new1") ...
7
votes
6answers
2k views

Is there any alternative to grep's -A -B -C switches (to print few lines before and after )?

grep -A 2 -B 3 prints 2 lines after the grep string and prints 3 lines before. grep -C 3 prints 3 Lines before and 3 lines after Unfortunately, the grep I'm using does not support these ...
7
votes
1answer
309 views

Is there a way to make perl -i not clobber symlinks?

A friend of mine points out that if you do: perl -pi.bak -e 's/foo/bar/' somefile when "somefile" is actually a symlink, perl does just what the docs say it will do: It does this by renaming ...