Need help joining lines

Hi All,

I need the command to join 2 lines into one. I found lots of threads but none give me the sollution. Probably because unix scripting is one of my best features :wink:

I got a logfile where line 2 needs to be joined with line 1, lines 4 needs to be joined with line 3 etc

If you need some more info please let me know.

TIA Rene

awk ' NR%2 {print $0}
        !NR%2 {printf("%s ", $0) } ' inputfile > newfile      
nawk 'NR%2 {printf $0} (NR+1)%2 {print FS $0}' infile.txt > outfile.txt

;);):wink:

sed 'N;s/\n/ /' infile > outfile

Thanks for the command's. Both awk and sed are not the solution. When I use

awk ' NR%2 {print $0} !NR%2 {printf("%s ", $0) } ' file_name

it will only list the lines 1,3,5 etc

the sed

sed 'N;s/\n/ /'

will only list the lines 2,4,6 etc

what about my solution? :confused:

I tried out the sed and works as expected..

 
$ cat joinme
I need the command to join 2 lines into one.
I found lots of threads but none give me the sollution.
Probably because unix scripting is one of my best features
I got a logfile where line 2 needs to be joined with line 1,
lines 4 needs to be joined with line 3 etc
If you need some more info please let me know.
 
$ sed 'N;s/\n//' joinme
I need the command to join 2 lines into one. I found lots of threads but none give me the sollution.
Probably because unix scripting is one of my best features I got a logfile where line 2 needs to be joined with line 1,
lines 4 needs to be joined with line 3 etcIf you need some more info please let me know.

Please post the command you are running and the output you are getting

sorry ahmed! nawk is not on the system.

xoops, I tried it in a new test and created the file like you, this is working so the command is ok.

Now looking at the file which needs to be changed. I think the end point of the lines are not ok. The file is comming from a windows environment.

This together triggered me to convert the file with dos2unix and now the command is working as expected.

Thank you guy's for helping me out here

You can use gawk or /usr/xpg4/bin/awk instead of nawk.:wink:

Thanks,

Maybe you can help me with this one aswel. I finally generated a file which lookes like this:

01/11/2010 9:34:00.15 4.14
01/11/2010 9:39:00.14 7.66
01/11/2010 9:44:00.40 6.77
01/11/2010 9:49:00.20 7.80
01/11/2010 9:54:00.14 7.52
01/11/2010 9:59:02.16 8.95
01/11/2010 10:04:00.16 5.51
01/11/2010 10:09:00.26 7.31

The second column is the time. I need to adjust this so only hh:mm:ss is displayed. As you can see the last 3 chars are not always on the same place. I'm trying to eddit is with sed but I get stuck on the wildcards to use.

TIA

use below:-

gawk -F"." '{$2=$3=""}1' OFS="\t" infile.txt

:cool::cool::cool:

o/p
01/11/2010 9:34:00
01/11/2010 9:39:00
01/11/2010 9:44:00
01/11/2010 9:49:00
01/11/2010 9:54:00
01/11/2010 9:59:02
01/11/2010 10:04:00
01/11/2010 10:09:00

You run off topic.
First try to fix the problem at the source, the way you generate your file, if you can't fix I'll suggest to start a new thread for your new problem.

or

gawk '{split($2,a,".") ; $2=a[1]}1'
o/p

01/11/2010 9:34:00 4.14
01/11/2010 9:39:00 7.66
01/11/2010 9:44:00 6.77
01/11/2010 9:49:00 7.80
01/11/2010 9:54:00 7.52
01/11/2010 9:59:02 8.95
01/11/2010 10:04:00 5.51
01/11/2010 10:09:00 7.31

:D:cool::stuck_out_tongue:

sed 's/\...//'

Damn I love you.......:b::D;):slight_smile:

---------- Post updated at 10:03 AM ---------- Previous update was at 09:58 AM ----------

your right, sorry for that!

(still a rookie who has to lurn a lot ;))

Same here :cool:

awk -F. '{$0=$1}1' 
bash-3.00$ nawk -F. '{$0=$1}1' infile.txt
01/11/2010 9:34:00
01/11/2010 9:39:00
01/11/2010 9:44:00
01/11/2010 9:49:00
01/11/2010 9:54:00
01/11/2010 9:59:02
01/11/2010 10:04:00
01/11/2010 10:09:00

danmero it is not the desired o/p .

desired o/p

01/11/2010 9:34:00 4.14
01/11/2010 9:39:00 7.66
01/11/2010 9:44:00 6.77
01/11/2010 9:49:00 7.80
01/11/2010 9:54:00 7.52
01/11/2010 9:59:02 8.95
01/11/2010 10:04:00 5.51
01/11/2010 10:09:00 7.31