i am a total SED noob so i hope that someone can help ..
very simply, i have a file with text:
white1
1
white2
0
white3
0
i would like to have it piped to a file that looks like the following:
white1 1
white2 0
white3 0
i have tried a couple of simple commands with no luck:
for example i want to see the entry with 1 to the right
sed -n /1/p file
gives this result:
white1
1
white2
white3
as i indicated, i am a noob but this should be easy .. any help would be appreciated and thanks
jgt
February 14, 2010, 11:25am
2
#!/usr/bin/ksh
while read color
do
read count
echo $color $count
done <text.file
Scott
February 14, 2010, 11:25am
3
Hi.
If you have only one number following each colour:
$ sed "N; s/\n/ /" file1
white1 1
white2 0
white3 0
$ xargs -n2 < file1
white1 1
white2 0
white3 0
paste -d" " - - < file1
white1 1
white2 0
white3 0
in perl
perl -wnle '! /^\d+/ and printf "$_ " or print $_ ;' infile.txt
;);)
wow, thank you all for the quick responses!!! this helps a ton .. as a noob i have been coding and learning for hours and finally hit a brick wall .. thanks again
or perhaps more easier:-
perl -wnle '$.%2 and printf "$_ " or print;' infile.txt
scottn .. xargs statement worked like a charm .. i was over thinking this lol
---------- Post updated at 11:49 AM ---------- Previous update was at 11:46 AM ----------
ahmad .. thank you for this as well
if you want more shorter code use below:-
perl -wp -e 's/^(\D\w+)\n/$1 /;' infile.txt