Reputation: 5509
Suppose i have the following input:
BSCTMC A13728, J02448, L13668, M14730, A12868, C11347,
L14203, C02285, A14419, BO0797, S12666, M12653,
D04841, S02825, T14713, L15004, C01972, E12057,
S13319
I want the A13728, J02448 (and so on) up to S13319 on the same line instead. I want to create a script that saves it to a text file. Thanks for your help.
Upvotes: 2
Views: 183
Reputation: 47189
You can do this with sed by only replacing newlines when the line ends with a comma (GNU sed):
sed ':a; /,$/ { N; ba }; s/\n//g' infile
If you also want to compress the whitespace from the alignment, add s/, */, /g
to the sed expressions, i.e.:
sed ':a; /,$/ { N; ba }; s/\n//g; s/, */ /g' infile
Output:
BSCTMC A13728, J02448, L13668, M14730, A12868, C11347, L14203, C02285, A14419, BO0797, S12666, M12653, D04841, S02825, T14713, L15004, C01972, E12057, S13319
Upvotes: 1
Reputation: 11489
If you don't care about the space in-between, you can use awk
:
awk '{printf "%s", $0}' inputfile > outputfile
Results :
BSCTMC A13728, J02448, L13668, M14730, A12868, C11347, L14203, C02285, A14419, BO0797, S12666, M12653, D04841, S02825, T14713, L15004, C01972, E12057, S13319
Upvotes: 0
Reputation: 3284
You can do this pretty easily with:
tr -d '\n' < filename.txt > filename-oneline.txt; mv filename-oneline.txt filename.txt
Upvotes: 1