Programming :: How To Append A String To A Next Line In Perl
Apr 9, 2010
I have a requirement like this..this just a sample script...
Code:
when i run this scipt...
Code:
Code:
It is appended in the same line...
I want it to be added to the next line.....
I want to do this by explitly using the filehandles in perl....and not with redirection operators in shell.
View 1 Replies
ADVERTISEMENT
Jun 8, 2010
I want to append a variable string to the end of a specific line. not like append the same string to each line. like in my file i have 4 columns, i want to add a string in 5th column in some fixed row.
View 4 Replies
View Related
Sep 20, 2009
I'm having problems completing my school exercises with awk.
Heres the desired outcome:
Code:
./my_awk 2
ACG GAG ATT AGG AGG ATC CCA CCA
CAC AGG ACG GAG ATT AGG AGG ATC
So it generates data in group of threes, 8 groups per row and prints it. My problem is that I can't seem to get awk to append stuff to string so I could print it nicely to screen. It just prints empty lines per the parameter given to it.
Heres my code so far:
Code:
#!/bin/sh
awk -v rows=$1 '
BEGIN {
[code]....
View 2 Replies
View Related
Apr 6, 2010
where I'm trying to demonstrate the file locking concept through Perl/CGI.Here is the script which I tried.
Code:
#!/usr/bin/perl -w
use strict;
use warnings;
print "Content-type: text/html
[Code].....
View 2 Replies
View Related
May 19, 2011
I have the following function that does not iterate through the array I want to be able to do some manipulation on each element in the array[@].it appears the below array has only one item in the array whereas i want the array to have 3 items hence the loop three times printing the message Any ideas why this is not happening ?
function foo() {
name =$1
array=( "$2" )
[code]...
View 5 Replies
View Related
Mar 24, 2011
How to list all the files that don't contain pattern1 and append a new line (pattern1) to those files before pattern2 only once.
pattern1 = /var/script/showMessage.sh
pattern2 = ;;
Code:
grep -c 'pattern1' /var/script/*_cam* | grep :0 | add pattern1 before pattern2 in each file loacted before.
View 10 Replies
View Related
Aug 10, 2010
The s means substitute
The $ in this particular regex (regular expression) means end of the line.
The ; is what you're subbing. This works fine and well, but what if you want to append a / at the end of the line?
sed 's/$///' filename doesn't work.
View 1 Replies
View Related
Jul 10, 2010
I want to know the Perl command to replace a string by pointing the line number. I know how to replace a string without pointing a line number but I am in need to replace only the two matching string in a file
View 6 Replies
View Related
May 3, 2011
I've been trying to understand pthread in C a little better. So I made a simple program that takes in a string from the command line and creates a thread to print the string. I've looked online and copied the basic concepts but there are something things I'm confused about. The programs works just fine, but I have questions. Here's what I have so far.
[Code]....
One thing I'd like to know is why the 3rd argument in the pthread_create function which is my SendMessage function needs to be typecasted to a void pointer and then send the address of the function. Also as for the 4th argument, I would see typecasting to void pointer in some of the pthread examples I saw online, but in my case I'm passing a char pointer, would this be correct? In which case would I ever want to pass a void pointer?
Do I need a pthread_exit(NULL) in my main and in the SendMessage function? If so, why? I added the sleep() function so that I could let the pthread_exit function in my SendMessage function execute first. I simply saw that the online examples on pthread had pthread_exit() in both locations.
View 6 Replies
View Related
Jan 29, 2011
What I am trying to achive is the editing of /etc/ssh/sshd_config I have the line
Code: AllowUsers usera userb
And I want to be able to append to the end of this line from a bash script.I have muddled together from other sites and got the following:-
Code: sed -e "s/^AllowUsers/� userc/" -i /etc/ssh/sshd_config
But this appears to add userc directly after AllowUsers and not after userb
View 2 Replies
View Related
Nov 6, 2010
Say I have a text file like:
Code:
1
3
4
How would I use ksh to put the number '2' into the second line of that file?Okay it's not bash, it's ksh because this computer is OpenBSD
View 14 Replies
View Related
Oct 16, 2010
I have a set of lines as ahown below:
Leon went to school
Leon came back from school..
Leon had dinner...
I have to replace the line containing "dinner" by a single string LUNCH...
View 2 Replies
View Related
Apr 15, 2009
I am thinking of appending something to each line in a text file with Java. I prefer not write a new file with content appended from the old one.That 'something' would probably be Time Stamp when the file is created (which is same for each line).I am not sure Java provide some easy way for it or not
View 3 Replies
View Related
Sep 15, 2010
One of my application generates a text file with an XML output in it. I need to read that log files and if the output does not match to a string in couple of tags it should create a log file with the file name and the the tag name.
The two tags where the string should match is:
Identity format tag should always be JPEG , well- formed and valid status tags should be true.
sample output file:
View 7 Replies
View Related
Sep 27, 2010
I want to read a input from user and output something like 'inputcd', which has to escape all backslashes if using double-quote. For instance, the following code would work.
Just curious if any other way I could do it without specify all backslashes? Since that takes much efforts when the sequence is long.
Code:
View 2 Replies
View Related
Jun 3, 2011
I am new to perl and not able to understand all the pattern matching.
I using this script to send the status to another Nagios server using ncsa. Nsca don't transmit "()" So I need to remove them before sending.
Currently I am using
Code:
for the string
Quote:
This is working fine but its is not working when there is change inside the bracket for e.g (6290)
I want to change this code to work for any change with in the brackets.
View 14 Replies
View Related
Jan 6, 2010
In my perl script I'd like to test if a string is written in uppercase letters or not. How can I do that? This type of test don't seem to work, so there must be other ways of doing this:
Code:
...return true.
I can create a subroutine that compares each character aginst a list of uppercase letters, but I'm hoping there's allready a build in routine in perl that does this...
View 14 Replies
View Related
Jun 30, 2011
I have question about replacing a string in a file.
How can I replace the printerb's 10.1.1.1 to something else(10.1.1.2, for example) without replace printera's 10.1.1.1 accidentally?
I have tried perl -e -pi "s/10.1.1.1/10.1.1.2/g" /etc/hosts. but, perl replace both 10.1.1.1 to 10.1.1.2.
View 13 Replies
View Related
Feb 28, 2011
At the moment I have a flat file which is being used by a few people. I want a script to remotely change the file, so I can start logging who is doing what.At this point here is one requirement I am trying to develop. We have text blocks who pretty much look like.I hope this is somewhat clear. I try to find $param for the right $workflow and change that. Can you help me to find $$var3 and change that?
View 1 Replies
View Related
Apr 1, 2009
Was wondering if any perl guru's could help me with a quick log file adjustment. I have a text file that looks like so (tabs and newlines are revealed so you can see what separates the data):
There are maybe 100 lines of text in this file at any given time. I need to delete all duplicate lines only looking at the first bit of text prior to the first tab. It doesn't matter which one gets deleted as long as there are no two lines that begin with that same text at the beginning before the first tab. So in this example, either the fist line "1234" or the last line "1234" would need to be deleted. I already have code in my script that opens the files - I just need the code to read the text into an array and the part that would find matches based on the above criteria, and make the deletions.
If it would be easier, I can even do a system call and use SED (v4.1.5) and/or AWK (3.1.5) instead.
View 7 Replies
View Related
Jan 9, 2010
how do you include a string variable as part of a regex in Perl?
View 5 Replies
View Related
Apr 15, 2011
What is the best way to merge lines, in sed, awk or perl, that occur between certain strings? I'm new to sed scripting and I have been working on this for some time now. I have a large file (sample below) that I need to edit.
What I need looks something like this.
I'm working with a very large file so simply merging all the lines then adding a new line character before ">contig" and after "translated" won't work, at least not with sed.
View 5 Replies
View Related
Jan 11, 2010
I am new to perl and am having trouble adding some strings together.
My full code is below:
The problem is $NewCommandB is always split into two lines, where the second line contains the "/atlas2/<blah>/<etc>/..." string. Since I am generating a .sh file to execute a lot of similar commands I need the string to all be on one line. Any idea why I get this behaviour and any suggestion on how to tell perl to make $NewCommandB a one line string?
Btw for completeness finalFileList.txt contains just file names one line after another:
View 5 Replies
View Related
Aug 2, 2011
I just learn perl script.May i know how to simplify the code below especially in the red color part? i saw some examples in internet, they use "next" command.
View 20 Replies
View Related
Apr 13, 2011
In a file,
I need to remove a part of string: /o
string:
or
the string can be
here I need to remove /d2
So, I need to remove everything after when I get last /
View 4 Replies
View Related
Jun 19, 2011
what's the equivalent code of Perl?sed -i 777,2545!d somefileObviously it extract lines of somefile between that 2 digits .
View 1 Replies
View Related
Feb 14, 2011
I wanted to find and replace a string from a perl file. I have written a script in bash which runs the following command.
perl -pi -e "s/$findstring/$replacestring/" testfile
where as $findstring = print F_WC_TMP"$line
";
and $replaceString = $line = join ' ', split ' ', $line; print F_WC_TMP"$line
";
But when I am running the above command, i think it is replacing the $findstring with the above mentioned string and hence it contains a $line, it is looking for the variable $line and not finding the exact string. I am confused about how to search for a string that contains $ in it and replace it with another $string.
View 5 Replies
View Related
Feb 4, 2010
I'm trying to chomp the new line character off of every 2nd line in a CSV file
[code]...
The above code gives me this error: Filehandle FILE opened only for output at SCR.pl line 7.
View 14 Replies
View Related
Aug 3, 2010
I need to output of a script to a file with tags.
I'm trying sed and was able to put a tag on the end of the line
Code:
Output is
Quote:
What I need to have is
Quote:
I'm thinking of I redirect my first sed command to a file and then use sed again to put <group> at the beginning of the line. My problem is how to put <group> to all beginning of the string.
View 2 Replies
View Related
Nov 28, 2010
Can you please let me know how can i append # in the begining of each line Based on a a search string lile /^8282##8282/gc
View 1 Replies
View Related