Home > front end >  Join multiple lines into single line
Join multiple lines into single line

Time:08-29

I have below piece of code, that created for Snowflake uploading.

    "8156bcee-eae2-4025-8c22-b70acc57f55f"|"65360414-0bd9-499e-ad0b-7eccde3c579d"|"11298717"|"1ad0aeb8-8135-491d-b28a-5f425afb9ca0"|"BDSA-2022-1742 does not affect used by ESP
 embedded Tomcat

https://nice.app.blackduck.com/api/vulnerabilities/BDSA-2022-1742/overview

This vulnerability only affects applications that happen to use form authentication based on example web application bundled with Tomcat."|"90252330-c1a7-48fb-9d99-4af8f60
dbefb"|"2022-06-24 14:29:26.272000"|"2022-07-06 17:25:50.882646"

How I can join these lines into a single line? I try remove enters by this command:

perl -pe 'chomp if /[^"\n]$/' $file  > /tmp/$file

CodePudding user response:

$ awk '{printf "%s", $0} END{print ""}' file
    "8156bcee-eae2-4025-8c22-b70acc57f55f"|"65360414-0bd9-499e-ad0b-7eccde3c579d"|"11298717"|"1ad0aeb8-8135-491d-b28a-5f425afb9ca0"|"BDSA-2022-1742 does not affect used by ESP embedded Tomcathttps://nice.app.blackduck.com/api/vulnerabilities/BDSA-2022-1742/overviewThis vulnerability only affects applications that happen to use form authentication based on example web application bundled with Tomcat."|"90252330-c1a7-48fb-9d99-4af8f60dbefb"|"2022-06-24 14:29:26.272000"|"2022-07-06 17:25:50.882646"

or maybe you'd prefer to put a blank between joined lines:

$ awk 'NF{printf "%s%s", sep, $0; sep=" "} END{print ""}' file
    "8156bcee-eae2-4025-8c22-b70acc57f55f"|"65360414-0bd9-499e-ad0b-7eccde3c579d"|"11298717"|"1ad0aeb8-8135-491d-b28a-5f425afb9ca0"|"BDSA-2022-1742 does not affect used by ESP  embedded Tomcat https://nice.app.blackduck.com/api/vulnerabilities/BDSA-2022-1742/overview This vulnerability only affects applications that happen to use form authentication based on example web application bundled with Tomcat."|"90252330-c1a7-48fb-9d99-4af8f60 dbefb"|"2022-06-24 14:29:26.272000"|"2022-07-06 17:25:50.882646"

CodePudding user response:

tr '\12' ' ' < $file > /tmp/$file

If you need the new line at the end, do echo "" after the tr command.

CodePudding user response:

This might work for you:

paste -sd' ' file

CodePudding user response:

jot -c - 65 126 |
  • single space
mawk 7 ORS=' ' 
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` 
a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ % 
  • gap-less
gawk 3 ORS=  
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ %
  • printf-free approach for gap-less plus trailing new-line
mawk -F'^$' 'END { print RS } !(ORS=_)'   
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
% 
  • sep'ed by the Apple-logo U F8FF () (wouldn't print correctly on Windows/Linux/Android/DOS/BeOS…
nawk 5 ORS='\357\243\277'
  ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
  abcdefghijklmnopqrstuvwxyz{|}~
  • using themselves as ORS as an unconventional way up to double up everything :
mawk2 'ORS = $_' 
AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ[[\\]]^^__``
aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~
  • make 4 extra copies each instead of just 1
nawk '(OFS = $_)(NF = 5)' ORS= | gsed -zE 's/.{65}/&\n/g'
AAAAABBBBBCCCCCDDDDDEEEEEFFFFFGGGGGHHHHHIIIIIJJJJJKKKKKLLLLLMMMMM
NNNNNOOOOOPPPPPQQQQQRRRRRSSSSSTTTTTUUUUUVVVVVWWWWWXXXXXYYYYYZZZZZ
[[[[[\\\\\]]]]]^^^^^_____`````aaaaabbbbbcccccdddddeeeeefffffggggg
hhhhhiiiiijjjjjkkkkklllllmmmmmnnnnnooooopppppqqqqqrrrrrsssssttttt
uuuuuvvvvvwwwwwxxxxxyyyyyzzzzz{{{{{|||||}}}}}~~~~~
  • have them increase in # of copies as function of input row order :
gawk '(OFS = ORS = $_) (NF = int(sqrt( NR )))'
AABBCCDDDEEEFFFGGGHHHIIIIJJJJKKKKLLLLMMMMNNNNOOOOPPPPPQQQQQ
RRRRRSSSSSTTTTTUUUUUVVVVVWWWWWXXXXXYYYYYYZZZZZZ[[[[[[\\\\\\
]]]]]]^^^^^^______``````aaaaaabbbbbbccccccdddddddeeeeeeefffffff
ggggggghhhhhhhiiiiiiijjjjjjjkkkkkkklllllllmmmmmmmnnnnnnnooooooo
pppppppqqqqqqqqrrrrrrrrssssssssttttttttuuuuuuuuvvvvvvvvwwwwwwww
xxxxxxxxyyyyyyyyzzzzzzzz{{{{{{{{||||||||}}}}}}}}~~~~~~~~
  • Related