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??
$ 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
perl -lane 'print $_ if ($.==1); printf("%s",$_) if($. >1)' inputfile
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
$ 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
$
1 Like
Hi,
Try this code,
nawk 'BEGIN{ORS="\n";}{if(NR==2){ORS="";}print;}' File
Cheers,
Ranga:)
yazu
7
(head -n1; tail -n+2 | tr -d '\n'; echo) <INPUTFILE
$ perl -lane 'if ($.==1){print $_;} else {printf("%s",$_);}' test
~dta.yunm
shhshsgggssssjsksjssggsjshsjsjssssshshshhshshshs