Perl is a high-level, general-purpose, interpreted, dynamic programming language. It was originally developed by Larry Wall as a general-purpose Unix scripting language to make report processing easier, over a period with support from open source community, it has evolved and matured to be used for ...
2
votes
4answers
46 views
Take a sum based upon particular columns
I am having a huge pile of data around 30 to 40 Million data. We need to process these files and send to another interface team.
Below is my file format which we recevie
c1 c2 c3 c4 c5 c6
A B ...
0
votes
2answers
10 views
Method to paste specific column when in terminal
I'd like to paste only the third column of data from within the terminal.
I originally have something like:
4 SF0086 SF0086
12 SF0087 SF0087
17 TSF141 TSF141
29 TSF070 TSF070
30 TSF028 TSF028
31 ...
6
votes
3answers
477 views
Is there a perl or awk solution for this problem?
I have an input file (input.txt) like below.
id1 id2 name weight
53723848 12651711 timburnes 1.36667
53530214 12651711 timburnes 1.51191
53723848 53530214 timburnes 1.94
764157 ...
4
votes
7answers
307 views
How can I groups numbers in a file
I have a file with numbers in float format.
I can review them via sort -rn numbers.txt | less
I would like though to be able to "group" them. I.e. easily see how many are in the same range.
To give an ...
6
votes
3answers
116 views
What is the difference between invoking a perl script via sh or perl
I have a simple Hello World perl script.
#!/usr/bin/perl
print 'Hello world.';
It works fine if I run it via perl <file_name>, but it fails I run it via sh <file_name>.
My ...
1
vote
3answers
63 views
Are there any difference using pipes?
Using Ubuntu 12.04.
Using pipes (5 times):
$ time echo XYZ | sed 's/X/A/g' | sed 's/Y/B/g' | sed 's/Z/C/g'
ABC
real 0m0.005s
user 0m0.000s
sys 0m0.000s
$ time echo XYZ | sed 's/X/A/g' | sed ...
4
votes
2answers
37 views
Regex this question format into LaTeX
1. Lorem ipsun la la la?
1. Sopor
2. Stupor
3. Torpor
2. A patient has Lorem?
1. Sopor
2. Stupor
3. Somnolentia
4. La
5. Coma
3. Doesn't Response to strong external irritants is short. Tendon, ...
2
votes
1answer
34 views
convert to epoch and back
I've used the following two perl command lines successfully:
perl -e 'use Time::Local; print timelocal(7,51,10,22,3,2014), "\n";'
which returns 1398163867, and
perl -e 'print ...
3
votes
2answers
33 views
How to overcome TZ difference on different servers?
We have a few servers in different timezones. We have a table.html that contains dates.
We want to have correct dates in each server, so we thought that:
- we should convert the time on server "A" ...
0
votes
0answers
15 views
Hit “sasl_decode error=-1” while sending mail via sendmail server on RHEL
Having installed sendmail and openwebmail on RHEL workstation 6.3, I can send email through webmail(cgi-bin/openwebmail/openwebmail.pl), but failed to interact with sendmail server in Perl script as ...
3
votes
4answers
80 views
merge 2 rows based on the same column values
I have a file like below.
47196436 47723284 name1 1.77273
42672249 52856963 name2 1.06061
52856963 430695 name2 1.16667
55094959 380983 name3 1.55613
17926380 55584836 name4 1.02461
3213456 34211 ...
2
votes
3answers
65 views
awk - to add a column after matching the remaining columns
I have a file (file1.txt) with the contents as below.
8145216 3377090 1.5
1405541 53595498 1.53637
I need to generate all the possible combinations for the first 2 columns in the above file. I use ...
1
vote
2answers
14 views
watch perldoc output preserving formatting
When I use watch to follow a perlpod documentation i am writing, the formatting gets mangeled (see NAME and Synopsis sections):
Every 2,0s: perldoc lib/Uki/Handlers/SOS.pm ...
3
votes
2answers
61 views
introduce line break at the same position based on another file
I have 3 input files all having the same number of lines. I have come up with a movie example to make the question look interesting.
file1.txt -- Essentially contains the actor names.
...
1
vote
3answers
73 views
Extract part of string using grep
I have 3 files in a directory
MYO144064T
MYO144064TA
MYO144064TX
Where the digits and 11th character will change.
In my csh script, I want to extract the letters 'A' and 'X' probably using grep
...
6
votes
2answers
110 views
Sorting with Perl respecting Locale Settings
Following data needs to be sorted respecting the locale sort order:
wird
sin
wär
pêche
war
Über
Uber
péché
peach
There was nor problem by using sort
$ sort < data
peach
pêche
péché
sin
Uber
...
1
vote
1answer
36 views
Adding timestamp before each STDOUT line inside perlscript
In a perl script, I am capturing all the STDOUT and STDERR using the below code:
open STDOUT, '>>', "$log_file" or die "Can't redirect STDOUT: $!";
open STDERR, ">&STDOUT" or die "Can't ...
4
votes
4answers
70 views
How to switch the first letters of two words?
$ echo 'foo bar' | sed SOMEMAGIC
boo far
$ echo 'one two' | sed SOMEMAGIC
tne owo
Q: in general, how can I replace the "b" from the "bar" to the "f" of the "foo"? And in reverse too, replace the "f" ...
1
vote
3answers
137 views
Print the last-but-one field
How to print the word before the last word in line (with ksh or awk or sed or perl one liner)
Example 1:
echo one two three
will print "two"
Example 2:
echo 1 2 3 4 5 6
will print "5"
2
votes
1answer
33 views
awk to split the input file into 2 files(one for duplicated values and one for unique values)
I have an input file like below.
file.txt
14 2.692022 author1 0
14 2.57826 author2 1
229 2 author3 2
323 2 author4 3
514 2.0625 author5 4
I am trying to split the file with the duplicated values ...
1
vote
0answers
56 views
Better approach to generating and adding contents to files
I have an input file like below.
1 First one
2 First two
3 First three
3 Second three
I am generating 2 output files like below.
#FILE1
1 First one
2 First two
3 First three
#FILE2
1 ...
0
votes
2answers
53 views
search for first pattern and copy the string inside the ( ) into the 3rd field in lines where the second pattern found
Here are my spec:
first search for "#firstpattern("
copy the content inside the ( ) to the 3rd field inside the ( ) of all lines where the "secondpattern" found.
remove the entire line with the ...
0
votes
0answers
57 views
replacement script multiple targets
I have this input file
Name=code_229633_138;isoforms=1
Name=code_229633_138
Name=code_229633_138;Target=R77_09738T0
Name=code_230519_1;isoforms=1
...
3
votes
2answers
116 views
case sensitive substitution; same target ids
I am struggled myself to make a case sensitive replacement in a text file. Please find below a segment of my sed file that I am running as
sed -f file.sed < input.txt > output.txt
...
1
vote
1answer
105 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 ...
0
votes
3answers
73 views
remove new lines
My input is a csv file like this:
10,"Special Projects,bangaram",0,,0
10,"Statutory/ Internal Audit , MO reporting (incl Excel Spreadsheet uploadation)
", bangaram,0,,0
10,"Complience with ...
2
votes
3answers
61 views
grab multiple lines after a matching target line
This question is similar to How to show lines after each grep match until other specific match? thus answers may be similar to those there.
I am trying to grab and extract from a file the lines that ...
1
vote
5answers
213 views
Can the string “abcedf” be matched to string “bafcde” in a single line command?
I am planning to implement an indexing structure in my program. For example, if I have 100 rows in the table, I will number these rows from 1 to 100 in another column by appending an _ to the end of ...
1
vote
4answers
102 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
180 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 ...
5
votes
2answers
479 views
Remove unknown unicode character from textfiles - sed, other bash/shell methods
I need to search and replace all occurences of an unknown character in some files having the same name.
Opening such files with vi, I read <91> code for that character.
Opening them with nano, I ...
1
vote
1answer
45 views
pcregrep fails due to segmentation fault
I am extracting the HTML source of a web page using the below command.
curl http://www.linkedin.com/pub/ramesh-venkataraman/63/621/b42 -s | w3m -dump -T text/html > foo.txt
The foo.txt has the ...
3
votes
3answers
246 views
extract only the substring after double quotes - grep
I have a file which is as below.
<a href="http://firstlink.com" title="title1">
<a href="http://secondlink.com" title="title2">
<a href="http://thirdlink.com" title="title3">
<a ...
1
vote
1answer
79 views
Is Perl ever a better tool than awk for text processing [closed]
This question was inspired by a discussion on stackoverflow - see in particular the comment thread under Ed Morton's answer.
I figured this was the site where I could get a definitive answer:
In ...
-2
votes
2answers
107 views
how to run perl cgi script on apache [closed]
I Successfully installed Apache web server in my local machine. My question is how to run perl cgi script on this server Actully I don't have any Idea that's why posted question here.
my sample cgi ...
4
votes
2answers
117 views
run perl script with unknown perl location
I'm developing a perl script which expected to be downloaded by Mac users with a very small knowledge of shell, linux etc, let's say office managers and accountants.
After the downloading the script ...
3
votes
1answer
49 views
Reorder Multiple Line Blocks with Sed
I am trying to reorder generated output as follows; given a tex fragment as follows, I want to move the /^Constant/ down below /Dummies/, with the line before and after /^Constant/. Further, I would ...
7
votes
2answers
112 views
Using empty line as context “group-separator” for grep
I need grep output with context, in color, and blank lines as group separator. In this question, I learned how to define custom group-separator, and I have constructed my grep command like this:
grep ...
-2
votes
3answers
72 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 ...
0
votes
2answers
104 views
perl one liners + match word and delete string after separator
I work with linux/solaris machines
and I need to add some rule in my ksh script:
Please advise how to match the password word in file, and delete the value password after the separator "=" with perl ...
0
votes
1answer
63 views
perl one liners + print line if match last word but with space
The following perl syntax will print the line in case line was ended with "DUPLEX"
But Sometimes DUPLEX have one space or more as
"DUPLEX "
so in this case line will not printed
Please ...
6
votes
1answer
200 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
35 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
431 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
81 views
Stuck installing TexLive from scratch on Debian KDE!
I'm trying to install TexLive 2013 on my Debian 7.3 kde desktop from scratch. I've read these guides (1 & 2) but instead of getting the perltk installer's GUI, I get the txt mode installer which I ...
4
votes
1answer
166 views
Using Modifiers of Perl-compatible Regex (PCRE) in grep
According to grep --help and man grep, we can use the -P option in order to interpret the pattern as a Perl regular expression (PCRE, to be precise), instead of the default POSIX basic regular ...
0
votes
2answers
50 views
Turning percentages into decimals?
I've got a CSV file that has percentages here and there expressed in text format, e.g.
173.91,0.00%,36.10%,1.71
Question of the day is how do I turn that example into
173.91,0,0.3610,1.71
Edit ...
0
votes
3answers
123 views
Shell attempts to interpret Perl script in spite of correct shebang [closed]
I have looked through the forums and I can't seem to find how to fix this. I have a very simple perl code that works fine on Windows, but when I try it on Linux and Solaris I get the following errors:
...
1
vote
1answer
95 views
Parsing csv with sed and perl one-liner?
I have a web server which stores configurations to PostgreSQL, and I plan to retrieve information from a certain table and then later parse it into csv format.
PAYLOAD
<?xml version="1.0" ...
2
votes
4answers
73 views
Print the string between two parentheses
I have file with these lines
G8 = P(G1,G3)
G9 = P(G3,G4)
G12 = P(G2,G9)
G15 = P(G9,G5)
G16 = P(G8,G12)
G17 = P(G12,G15)
I need the output as
G1,G3
G3,G4
.....
How can I do it with sed/grep ...