Inserting semicolon at the end of a line

HI

Am totally confused with sed and translate command command.. My problem is

I have a file like

# vi test.csv
ABC_IMUY
ERD0_FN
VEG_NON_DES_IYT
BUY4_FLOW
POI_SHD_URDF_IYUT_REDS_CYC
UYT_PMC4_WIND
EX_FRE_FRD_L2_REF_FLICT
JHY_SGT_DSE_L2
IYO_HYTR_FGT_L3_BGT_ICT
CICO_MCX_MCOIE_L3.1_DSA
VGRE_BUWTE_YIURE_RL2L3_SHR
VT_TYEW_UEV_LL4
KODK_IWJXMX_MXEWI_L2ISS_BYW
MOSW_NAS_NIRS_L2_OIY_DSE

I used translate command as
tr '\n' ';' test1.csv > test1.csv_1

I got the output as

ABC_IMUY;ERD0_FN;

But I need the output as

# vi test.csv
ABC_IMUY;
ERD0_FN;
VEG_NON_DES_IYT;
BUY4_FLOW;
POI_SHD_URDF_IYUT_REDS_CYC;
UYT_PMC4_WIND;
EX_FRE_FRD_L2_REF_FLICT;
JHY_SGT_DSE_L2;
IYO_HYTR_FGT_L3_BGT_ICT;
CICO_MCX_MCOIE_L3.1_DSA;
VGRE_BUWTE_YIURE_RL2L3_SHR;
VT_TYEW_UEV_LL4;
KODK_IWJXMX_MXEWI_L2ISS_BYW;
MOSW_NAS_NIRS_L2_OIY_DSE;

Please help..:confused:

Try this

awk '{$2=";"}' test.csv

or

sed 's/$/;/' test.csv

The translate command works by character. In your code, the newline command is replaced by ";" and the newline disappears. Hence all the lines are merged into a single line.

why arent u using sed?

 
sed 's/$/;/g' filename
1 Like
awk '{$2=";"}' test.csv

This not working..

Am using ksh shell..

---------- Post updated at 01:47 AM ---------- Previous update was at 01:44 AM ----------

sed 's/$/;/g' filename

This works very fine.. Thanks

I missed to include the print instruction. Corrected in the below statement.

awk '{$2=";"}1' test.csv 
1 Like

Some awk variation
awk '{print $0";"}' test.csv
awk '{$0=$0";"}1' test.csv
awk 1 ORS=";\n" test.csv

awk '{$2=";"}'
May not be a good solution of the file does contain more than one filed and the purpose is to get ; at end of every line