-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all! CAn anyone help me with a PERL (or other scripting language) oneliner? Problem; I have a file with the layout; Item1 - description 1 Item2 - Description 2 Item3 - Description 3 .... All lines are the same layout, but the Item differs in lenght. Item(n) is always one word (different lenghts The delimiter is allways " - " (<space>-<dash><space>) The Description is one or more sentences (all on one line) I want the file to be converted to; "Item1 Item2 Item3...." How do i do that? I tries fiddling with cut and grep but to no avail... - -- /Rikard - ------------------------------------------------------------------------------------ Rikard Johnels email : rikjoh@norweb.se Web : http://www.rikjoh.com Mob : +46 (0)735 05 51 01 - ------------------------ Public PGP fingerprint ---------------------------- < 15 28 DF 78 67 98 B2 16 1F D3 FD C5 59 D4 B6 78 46 1C EE 56 > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQFA1X0RWdS2eEYc7lYRAui3AJ4v4NNWoa2NV7OpyIhwgH4FVivgvgCg6ZCg 7R/xukJm9MFQZeiZUQCNl1U= =WDg9 -----END PGP SIGNATURE-----
Try this one: perl -e 'foreach (<>) { chomp; s/(.* )- .*/\1/; print;}' filename HTH, Eric On Sunday 20 June 2004 14:03, Rikard Johnels wrote:
Hello all! CAn anyone help me with a PERL (or other scripting language) oneliner?
Problem; I have a file with the layout; Item1 - description 1 Item2 - Description 2 Item3 - Description 3 ....
All lines are the same layout, but the Item differs in lenght. Item(n) is always one word (different lenghts The delimiter is allways " - " (<space>-<dash><space>) The Description is one or more sentences (all on one line)
I want the file to be converted to; "Item1 Item2 Item3...."
How do i do that? I tries fiddling with cut and grep but to no avail...
--
/Rikard
--------------------------------------------------------------------------- --------- Rikard Johnels email : rikjoh@norweb.se Web : http://www.rikjoh.com Mob : +46 (0)735 05 51 01
------------------------ Public PGP fingerprint ---------------------------- < 15 28 DF 78 67 98 B2 16 1F D3 FD C5 59 D4 B6 78 46 1C EE 56 >
Op zondag 20 juni 2004 14:03, schreef Rikard Johnels:
I have a file with the layout; Item1 - description 1 Item2 - Description 2 Item3 - Description 3 ....
All lines are the same layout, but the Item differs in lenght. Item(n) is always one word (different lenghts The delimiter is allways " - " (<space>-<dash><space>) The Description is one or more sentences (all on one line)
I want the file to be converted to; "Item1 Item2 Item3...."
How do i do that? I tries fiddling with cut and grep but to no avail...
awk '{printf("%s ", $1)} END {print ""} ' <file> -- Richard Bos Without a home the journey is endless
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sunday 20 June 2004 14.47, Richard Bos wrote:
Op zondag 20 juni 2004 14:03, schreef Rikard Johnels:
I have a file with the layout; Item1 - description 1 Item2 - Description 2 Item3 - Description 3 ....
All lines are the same layout, but the Item differs in lenght. Item(n) is always one word (different lenghts The delimiter is allways " - " (<space>-<dash><space>) The Description is one or more sentences (all on one line)
I want the file to be converted to; "Item1 Item2 Item3...."
How do i do that? I tries fiddling with cut and grep but to no avail...
awk '{printf("%s ", $1)} END {print ""} ' <file>
-- Richard Bos Without a home the journey is endless
Thank you! Eric Synaeve's perl was somewhat successful, It trapped a " - " in the comment field, and thus produced a slightly faulty file. (easily editable tho) The awk script was 100% accurate in reformatting the file. Thank you both! - -- /Rikard - ------------------------------------------------------------------------------------ Rikard Johnels email : rikjoh@norweb.se Web : http://www.rikjoh.com Mob : +46 (0)735 05 51 01 - ------------------------ Public PGP fingerprint ---------------------------- < 15 28 DF 78 67 98 B2 16 1F D3 FD C5 59 D4 B6 78 46 1C EE 56 > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD4DBQFA1ZUdWdS2eEYc7lYRAuvxAJwMNzdzY0aFHdngC7yOV14SyzFT1ACWMfpH zbNw9TbYA9Oad33zOBUURg== =eze8 -----END PGP SIGNATURE-----
participants (3)
-
Eric Seynaeve
-
Richard Bos
-
Rikard Johnels