concatinate all lines from second line to end of line in perl


 
Thread Tools Search this Thread
Top Forums Programming concatinate all lines from second line to end of line in perl
# 1  
Old 09-28-2011
Data concatinate all lines from second line to end of line in perl

I have datafile like
~dta.yunm
shhshsgggssssjsksjs
sggsjshsjsjssss
shshshhshshshs


i wish to take only first line and all other lines in concatenated form in second line what should I do???
output like

~dta.yunm
shhshsgggssssjsksjssggsjshsjsjssssshshshhshshshs


please tell me how can i do this in perl??
# 2  
Old 09-28-2011
Code:
 
$ nawk 'NR==1{print} NR>1{printf("%s",$0)}' inputfile

---------- Post updated at 09:51 AM ---------- Previous update was at 09:17 AM ----------

perl solution

Code:
 
perl -lane 'print $_ if ($.==1); printf("%s",$_) if($. >1)' inputfile

# 3  
Old 09-28-2011
thanks. but it dose not print next lines of input file, it concatenated form this code extract first line only. I wish to get result as


~dta.yunm
shhshsgggssssjsksjssggsjshsjsjssssshshshhshshshs


from input file

~dta.yunm
shhshsgggssssjsksjs
sggsjshsjsjssss
shshshhshshshs
# 4  
Old 09-28-2011
Code:
 
$ cat test
~dta.yunm
shhshsgggssssjsksjs
sggsjshsjsjssss
shshshhshshshs

$ perl -lane 'print $_ if ($.==1); printf("%s",$_) if($. >1)' test
~dta.yunm
shhshsgggssssjsksjssggsjshsjsjssssshshshhshshshs
$
 
$nawk 'NR==1{print} NR>1{printf("%s",$0)}' test
~dta.yunm
shhshsgggssssjsksjssggsjshsjsjssssshshshhshshshs
$

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 09-28-2011
AWK

Hi,

Try this code,

Code:
nawk 'BEGIN{ORS="\n";}{if(NR==2){ORS="";}print;}' File

Cheers,
RangaSmilie
# 6  
Old 09-28-2011
thanks

thank you... Smilie
# 7  
Old 09-28-2011
Code:
(head -n1; tail -n+2 | tr -d '\n'; echo) <INPUTFILE

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

Perl to extract values and print at end of each line

In the below perl I am trying to extract and print the values AF1=, the GT value, and F or QUAL diveded by 33 (rounded to the nearest whole #). The GT value is at the end after the GT:PL so all the possibilities are read into a hash h, then depending on the value that is in the line the... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

Delete lines that contain a pattern from specific line to the end.

Gents, I am trying to delete all lines which start with "H" character, but keeping the fist header. Example In the input file I will delete all lines starting from line 8 which contents character "H" to the end of the file. I try sed '8,10000{/^H/d;}' file But as don't know the end... (1 Reply)
Discussion started by: jiam912
1 Replies

4. UNIX for Dummies Questions & Answers

Grep lines with numbers greater than 2 digits at the end of the line

I'm trying to grep lines where the digits at the end of each line are greater than digits. Tried this but it will only allow me to specify 2 digits. Any ideas would greatly be appreciated. grep -i '\<\{3,4,5\}\>' file ---------- Post updated at 05:58 PM ---------- Previous update was at 05:41... (1 Reply)
Discussion started by: jimmyf
1 Replies

5. Shell Programming and Scripting

Append text to end of line on all lines

Hi, I've spent some time researching for this but can't seem to find a solution. I have a file like this 1234|Test|20101111|18:00|19:00There will be multiple lines in the file with the same kind of format. For every line I need to make it this 1234|Test|20101111|18:00|19:00||create... (5 Replies)
Discussion started by: giles.cardew
5 Replies

6. Shell Programming and Scripting

Adding lines at end of a line

This is what I want to do. I want to write a script that reads each line (of the highlighted file below) and add a specific number of blank lines (sometime 2, 3 or 5 lines) at the end of each line while copying that line. For example, here is the input. The sky is blue. I like to eat. I like... (19 Replies)
Discussion started by: Ernst
19 Replies

7. Programming

How to write a new line to the end of the file in Perl?

i am very new to Perl. i am using Ubuntu. i have a string call $string that contains following words "new line". i also have a data file as follows. djfibjbet etitrbjijbtr rrge rgjierjegjeri jerijg kijij jijij i want to write my new line to my data file as follows. djfibjbet... (3 Replies)
Discussion started by: usustarr
3 Replies

8. UNIX for Advanced & Expert Users

need to concatenate two lines if the line doesnt end with quotes

Hi I am getting a source file where the columns are seperated by comma and double Quotes Eg1 : "AAA","BBB","CCCC" in the same source file i am also getting few lines where my last columns double quotes are ending in its next line or the next next line Eg2: "AAA","BBB","CCC CC"... (9 Replies)
Discussion started by: laxmi131
9 Replies

9. Shell Programming and Scripting

Removing end of line to merge multiple lines

I'm sure this will be an easy question for you experts out there, but I have been searching the forum and working on this for a couple hours now and can't get it right. I have a very messy data file that I am trying to tidy up - one of the issues is some records are split into multiple lines: ... (4 Replies)
Discussion started by: tink
4 Replies

10. Shell Programming and Scripting

check position of end of line for some specific lines

-------------------------------------------------------------------------------- Have to check in a file that the lines starting with 620 and 705 are ending at same posiotin. 82012345 62023232323 70523949558 62023255454 9999 In the above lines, i have to check the lines starting... (1 Reply)
Discussion started by: senthil_is
1 Replies
Login or Register to Ask a Question